declare @default sysname, @sql nvarchar(max)
select @default = name
from sys.default_constraints
where parent_object_id = object_id('MYTABLENAME')
AND type = 'D'
AND parent_column_id = (
select column_id
from sys.columns
where object_id = object_id('MYTABLENAME')
and name = 'MYCOLUMNNAME'
)
set @sql = N'alter table MYTABLENAME drop constraint ' + @default
exec sp_executesql @sql
alter table MYTABLENAME drop column MYCOLUMNNAME
go
Remplazar MYTABLENAME por el nombre de la tabla y MYCOLUMNSAME por el nombre de la columna.
Excelente aporte
ResponderEliminar