We help IT Professionals succeed at work.

DROP every constraint

Hi guys

Question:  When you drop a table, how do you ensure that you drop every constraint on the table first?

<pseudo code>

IF OBJECT_ID('log.EXECUTIONS','U') IS NOT NULL
      begin
      ALTER TABLE log.EXECUTIONS DROP CONSTRAINT <every friggin' constraint on the table>   --  <--  Here
      DROP TABLE log.EXECUTIONS
      end
GO

Thanks in advance.
Jim
Comment
Watch Question

Senior DBA
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
Dropping the table itself will automatically drop every constraint in the table.
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Author

Commented:
I changed the order of my DROPS so that all the children were dropped first, then the parent, and I no longer get these messages.
I'm going to wait a couple of days to make sure that is correct.

Thanks.
Jim
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Author

Commented:
Haven't had a chance to circle back to this, sorry, but reordering the DROPs based on child-parent order seems to have worked.  Thanks.