qevriq
Last Updated: February 25, 2016
·
273
· gifthlong

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)