I like foreign keys, but I have one problem with them. I have a conversion program where I turn off foreign keys for tables. The reason I do this is because I can convert all the records to the main table, but leave the rest of the tables dependent on this untouched, without relearning them every time, because they are HUGE.
I use these commands to disable and re-enable foreign keys:
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint
However, after you re-enable the "Check Existing Data for Creation or Re-Enable" constraint, the value is still set to No. I understand that it is set to "No" because I disabled the restriction, but by doing this, he changed my database schema, which I do not like. I thought this would be seen as re-enabling the constraint and would check for existing data, but apparently not.
Is there no way to change this with the ALTER TABLE command? I know that I can if I drop the constraint and recreate it, but I am not going to write a script to recreate every foreign key that I have and maintain it.
I am using SQL Server 2008 R2.
source share