.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to check referential integrity

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :Sql Server

Hi there!

I have a database (MS SQL 2005) in which I have imported a lot of data. During the import I turned off the foreign key constraints. Is there a way to check, which rows in a table or across the whole database are violating the foreign key constraints? Is there any sql statement for this?

Thank you for your help!


Cya, Mike

View Complete Post

More Related Resource Links

About Cascading - Simple Filtering versus "Referential Integrity"

Hola,   It seems that the term "cascading" has not been differently understood by the ASP.Net community.   Most people writing about "cascading" makes you feel like is something that only has to do with "filtering" and nothing else.   I have been trying to understand for almost one year what is all about behind the scenes to make "cascading" work, and it is true that passing values of variables has been a gigantic issue but "not the issue" because when you can do that (passing values) you realize that such things is not simply enough and IT IS NOT THE ASNSWER YOU ARE LOOKING FOR.   I have found many ways of passing these values. I have worked on different approaches and some of them seems to work better than other, more efficient, with less code, with less downgrade in performance, with less calls to the database, etc.   But the "real issue" of cascading is not that, so I'm wondering: How can you make (call it "customize") that the REFERENTIAL INTEGRITY among all different FKs could be maintainded at "DATA LEVEL"?   What I am trying to say is ... ...   Ok! ... Let's suppose you already know how to pass the values of some pre-customized filters to your Insert.aspx page (or any other page) and the dropdowwnlists are shown ok! ... ... ... BUT ... ... ... 

how to remove Referential Integrity rules?


I am making a form that reads/writes to a table called Contract.  Contract has a field called BuyerID, which is used to store the PK of a record in the Organization table, OrganizationID.  When I first tried saving my form, I got the following exception:

The record can't be added or changed. Referential integrity rules require a related record in table 'Organization'.
The transaction ended in the trigger. The batch has been aborted.

When I choose a value for the field that gets assigned to BuyerID, I don't get an exception.  I don't want this field to be required, so I need to remove the referential integrity rule.

I thought there must be a foreign key constraint specifying that BuyerID points to Organization.OrganizationID.  However, running

EXEC sp_help 'Contract'

shows that the only constraint for BuyerID is a default value of 0.  Any ideas on how to remove the referential integrity rule?

SQL 2008 Integrity Check Mintenance Plan Errors



I have setup a maintenance plan that does an integrity check on selected databases, when the job runs it errors with the following error:

Executed as user: {Server name\username}. Microsoft (R) SQL Server Execute Package Utility  Version 10.0.1600.22 for 32-bit  Copyright (C) Microsoft Corp 1984-2005. All rights reserved.    Started:  09:04:10  Progress: 2010-10-26 09:04:16.57     Source: {202B6BA7-A187-4C97-9CF9-E7614391EF2C}      Executing query "DECLARE @Guid UNIQUEIDENTIFIER      EXECUTE msdb..sp...".: 100% complete  End Progress  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  09:04:10  Finished: 09:04:19  Elapsed:  8.609 seconds.  The package execution failed.  The step failed.

I have taken the t-sql from the job and put it in another maintenance task, this runs with no problem.

All other jobs run fine on the server and this doesent happen to any other server in the company, all sql servers are configured the same and are of the same patching level.

What should i look at next to fix this problem.

Many thanks in advance.

Viewstate verification failed. Reason: The viewstate supplied failed integrity check.



I'm getting the following error in my event log appears many times each hour,  if somebody could shed some light it would be very nice...  Also I am running server 2008 web server,  this is NOT a webfarm.


- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

- <System>

<Provider Name="ASP.NET 4.0.30319.0" />

<EventID Qualifiers="16384">1316</EventID>




<TimeCreated SystemTime="2010-11-15T19:58:53.000000000Z" />




<Security />


- <EventData>


<Data>Viewstate verification failed. Reason: The viewstate supplied failed integrity check.</Data>

<Data>11/15/2010 2:58:53 PM</Data>

<Data>11/15/2010 7:58:53 PM</Data>




Maintenance Plans - Check Database Integrity Error

Executing query "DECLARE @Guid UNIQUEIDENTIFIER      EXECUTE msdb..sp...".: 100% complete  End Progress  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  9:04:40 AM  Finished: 9:04:41 AM  Elapsed:  0.842 seconds.  The package execution failed.  The step failed.

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

check box control


Hi ,

I have a three check box in my web form ,i need to choose only one check box, if i choose one check box

another 2 check box automatically unchecked

can i use jquery for check box

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

how to check a textbox value in jquery?



I want to perform some action when an asp.net textbox value length is greater than 1 character. And for this I wanted to know how to write this check in jquery?

I have created a check like below-

if ($('[id=txtUserInput]').val().length > 2)
{ do some work...} 

But its giving me the following error

$("[id=txtUserInput]").val() is undefined

Can anybody let me know the right way of doing this?



How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

Automatically redirect to HTTPS and check if SSL is active



I've set in the web.config:

    <!-- User Authentication -->
    <authentication mode="Forms">
      <forms loginUrl="~/Page/View/Content/Login.aspx" timeout="2880" requireSSL="true" />

This works fine. If there is no ssl connection, the login form doesn't continue. But I would like to check if ssl is active (in codebehind) and, if it's possible, to automatically the user to the https page if he's currently on http. (I could do this job by manually redirect with page.response("https://url.../login.aspx"); but this is not really generic. For example if the webapp is moved to another domain it doesn't work anymore... I'm looking for something like: FormsAuthentication.RedirectWithSSL(); or so... :D)


how to check which pages of my site that my visitor visiting at the moment


 Hi all, and thanks a lot for the replies since now. I have a new question :

I prepared a simple instant messaging system for my web site and i would like to learn which visitor (registered member) is at which page of my site. 

For example : 

Uid:10000, Username:donald, NameSurname:Donald DUCK is a registered and signed in visitor.

I need the code which tells me that visitor is at which page (ie. images.aspx?imageid=143223)

Sorry for my poor english, and let me know if i should explain more clearly :)

Have a good evening...

Tools for memory error check in VS2005


Dear all,

I am going to write vs2005 program with ASP.NET and C++.

As you know that C++ will involve a lot of memory error handling.

Do you know is there any tools for checking memory error in Code Behind C++??

Team System: Check-in Notes and Policies


Learn how to add check-in notes and check-in policy support to a Word add-in, in this fifth and final installment of an ongoing discussion.

Brian A. Randell

MSDN Magazine Launch 2008

Team System: Custom check-in policies


Team Foundation Server provides APIs that let you create check-in notes (categorized string data) and custom check-in policy implementations. These features combine to give project administrators better control over the group development process.

Brian A. Randell

MSDN Magazine November 2007

Toolbox: Create Graphs, Send E-Mail, Spell-Check, and More


Turn boring data into stunning graphs, create, parse, send, and receive mail messages from code, and more.

Scott Mitchell

MSDN Magazine August 2007

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend