Created
May 20, 2014 05:58
-
-
Save Solstice1557/cd151fdf4446f8495ce9 to your computer and use it in GitHub Desktop.
Drop column with constraints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @sql NVARCHAR(MAX) | |
WHILE 1=1 | |
BEGIN | |
SELECT TOP 1 @sql = N'alter table TABLE_NAME drop constraint ['+dc.NAME+N']' | |
from sys.default_constraints dc | |
JOIN sys.columns c | |
ON c.default_object_id = dc.object_id | |
WHERE | |
dc.parent_object_id = OBJECT_ID('TABLE_NAME') | |
AND c.name = N'COLUMN_NAME' | |
IF @@ROWCOUNT = 0 BREAK | |
EXEC (@sql) | |
END | |
GO | |
alter table TABLE_NAME drop column COLUMN_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment