Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @table_name nvarchar(256) = N'table';
- declare @col_name nvarchar(256) = N'column';
- declare @constraintName nvarchar(1000);
- select @constraintName = d.name
- from sys.tables t
- join sys.indexes d on d.object_id = t.object_id and d.type=2 and d.is_unique=1
- join sys.index_columns ic on d.index_id=ic.index_id and ic.object_id=t.object_id
- join sys.columns c on ic.column_id = c.column_id and c.object_id=t.object_id
- where t.name = @table_name and c.name=@col_name
- EXEC('ALTER TABLE ' + @table_name + ' DROP CONSTRAINT ' + @ConstraintName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement