Disabling and Enabling Table Constraints

Back in the ages of pre-Sql Server 2005, we had to drop and re-create constraints to modify certain data. I guess it was habit when I found myself beginning to do this today. Fortunately, I remembered the newer-improved way (of course, I DID have to look it up). Instead of dropping and re-creating constraint,s they can simply be disabled and enabled:

ALTER TABLE testTable NOCHECK CONSTRAINT FK_testTable_Task

–do your data deletes, etc here

ALTER TABLE testTable CHECK CONSTRAINT FK_testTable_Task

Voila, no risky dropping involved. Of course, be careful when manipulating your data in such a manner. This should not be normal practice.