{"id":114,"date":"2011-01-18T19:10:00","date_gmt":"2011-01-19T01:10:00","guid":{"rendered":"https:\/\/www.chrystalsander.com\/blog\/?p=114"},"modified":"2023-07-26T12:31:39","modified_gmt":"2023-07-26T17:31:39","slug":"disabling-and-enabling-table-constraints","status":"publish","type":"post","link":"https:\/\/www.chrystalsander.com\/blog\/?p=114","title":{"rendered":"Disabling and Enabling Table Constraints"},"content":{"rendered":"<p>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:<\/p>\n<p style=\"\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">      <span style=\"color: green;\">ALTER TABLE testTable NOCHECK CONSTRAINT FK_testTable_Task<\/span><\/span><\/p>\n<p style=\"\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">      <span style=\"color: green;\">&#8211;do your data deletes, etc here<br \/><\/span><\/span><\/p>\n<p style=\"\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">      <span style=\"color: green;\">ALTER TABLE testTable CHECK CONSTRAINT FK_testTable_Task<\/span><\/span><\/p>\n<p style=\"\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"color: green;\"><\/span><\/span>Voila, no risky dropping involved.  Of course, be careful when manipulating your data in such a manner.  This should not be normal practice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.chrystalsander.com\/blog\/?p=114\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Disabling and Enabling Table Constraints&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[56,50],"_links":{"self":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114"}],"collection":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":1,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}