Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

21
  • 10
    "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all" Should there be only one "CHECK" there? Commented May 3, 2011 at 14:53
  • 33
    @CrazyPyro - no you need both Commented May 4, 2011 at 13:35
  • 39
    @CrazyPyro: both are indeed needed, reason for that is because the first CHECK belongs with the WITH and the second CHECK with the CONSTRAINT (it's the type of constraint). The first CHECK ensures your data gets checked for consistency when activating the constraint. If you don't want that, you could write WITH NOCHECK. Can be useful in certain test situations when you don't care about the actual data, as long as there is some so that your queries have something to play with. Commented Jan 20, 2012 at 9:39
  • 48
    It's worth noting that even with constraints disabled, TRUNCATE TABLE won't work. For that, you will need to drop the constraints. Otherwise, use DELETE FROM, but take into consideration the difference: mssqltips.com/sqlservertip/1080/… Commented Dec 10, 2012 at 11:12
  • 25
    This is very dangerous! This will enable constraints that had been previously disabled. select * from sys.foreign_keys where is_disabled = 1 tells you if you have this scenario. Commented Apr 20, 2017 at 20:07