drop default constraint on table
declare @table_name nvarchar(256) = 'foo',
@col_name nvarchar(256) = 'foocol'
declare @Command nvarchar(1000)
select @Command = 'ALTER TABLE ' + @table_name + ' drop constraint ' + d.name
from sys.tables t
join sys.default_constraints d on d.parent_object_id = t.object_id
join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id
where t.name = @table_name and c.name = @col_name
if @Command is not null
execute (@Command)
Written by Gift
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#T-sql
Authors
Related Tags
#t-sql
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#