SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Detect invalid FK-data after using "WITH NOCHECK"

By Johan Bijnens, 2007/05/15

Total article views: 135 | Views in the last 30 days: 6

In situations where FK's have been created using the "WITH NOCHECK" option you can get into troubles because the FK-data is not checked ! (so there may be invalid data in the FK-column !)

E.g. ALTER TABLE [dbo].[mytable] WITH NOCHECK add constraint [FK__USED_RESO__Actio__1162CF5F] FOREIGN KEY ( Action_Type ) REFERENCES [dbo].[Action_Types] ( Action_Type )

BOL states "... If you do not want to verify new CHECK or FOREIGN KEY constraints against existing data,
use WITH NOCHECK.
We do not recommend doing this, except in rare cases. ..."


I've commented the proc because I found the DBCC command that does even more than that !

By Johan Bijnens, 2007/05/15

Total article views: 135 | Views in the last 30 days: 6
Your response
 
 
Related tags
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com