1

I am quite new to databases.

Is there a simple way to check on all tables of a DB if all foreign key values match an existing primary key value ?

Actually I am using a tool (Red Gate) to move many data of many tables from a database to another. I would like to check some kind of consistency after the work is complete.

The SQL script generated by the tool starts with ALTER TABLE ... NOCHECK CONSTRAINT ..., and ends with ALTER TABLE ... CHECK CONSTRAINT ..., maybe the work was already done by the script...

Any help greatly appreciated !

Sylvain B.
  • 719
  • 5
  • 31
  • 1
    If it's `WITH CHECK CHECK CONSTRAINT` the statement validates the constraint. Check [Can you trust your constraints?](http://sqlblog.com/blogs/hugo_kornelis/archive/2007/03/29/can-you-trust-your-constraints.aspx) for an explanation – Panagiotis Kanavos Feb 08 '17 at 15:49
  • @Panagiotis : Thanks for the link. I get `The ALTER TABLE statement conflicted with the FOREIGN KEY constraint ....` :) – Sylvain B. Feb 08 '17 at 15:59
  • Found maybe a related question : http://stackoverflow.com/questions/1098554/sql-server-how-to-make-server-check-all-its-check-constraints – Sylvain B. Feb 08 '17 at 16:08
  • Your comment to Panagiotis is unintelligible. DId his comment answer your question? – philipxy Feb 15 '17 at 02:56
  • @philipxy : to answer your comment, I have found what I needed in Panagiotis' comment and in the related question I mention. In the second sentence of my comment, I was somehow telling my story to the community by saying the script I was using (generated by the tool) was braking foreign key relationships in my database. This is why i put a smiley :) – Sylvain B. Feb 16 '17 at 12:20

0 Answers0