Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete column with constraints

Status
Not open for further replies.

Mack2

Instructor
Joined
Mar 12, 2003
Messages
336
Location
US
I have a lot of columns with constraints to delete. Is there a way to have the code still delete the column even if it has a constraint? Or do I have to go through and delete every constraint first, then delete the column.
Thanks in advance!
 
See ALTER TABLE in SQL BOL. You can disable/enable all foreign key and check constraints on a table.

--disable constraints
ALTER TABLE YourTable NOCHECK CONSTRAINT ALL

<delete rows>

--enable constraints
ALTER TABLE YourTable CHECK CONSTRAINT ALL

If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
I did try that, I took code from bol and I received an error. It seems like what you suggested will work. I dont know if I have the code wrong
Thanks for your help, and nice web site!
Stacy

 
This is my code, it may be something very basic that I am missing, I am new to transact sql

ALTER TABLE doc_exb DROP COLUMN column_b
NOCHECK CONSTRAINT ALL
GO

Thanks in advance!
 
I apologize. I thought you were deleting rows from a table. If you are dropping a column from a table you must first drop the constraint. If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top