여러 항목을 default constraints or check constraints
만든 일부 열에 유용합니다 .
수정 된 https://stackoverflow.com/a/16359095/206730 스크립트
참고 :이 스크립트는 sys.check_constraints 용입니다.
declare @table_name nvarchar(128)
declare @column_name nvarchar(128)
declare @constraint_name nvarchar(128)
declare @constraint_definition nvarchar(512)
declare @df_name nvarchar(128)
declare @cmd nvarchar(128)
PRINT 'DROP CONSTRAINT [Roles2016.UsersCRM].Estado'
declare constraints cursor for
select t.name TableName, c.name ColumnName, d.name ConstraintName, d.definition ConstraintDefinition
from sys.tables t
join sys.check_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 = N'Roles2016.UsersCRM' and c.name = N'Estado'
open constraints
fetch next from constraints into @table_name , @column_name, @constraint_name, @constraint_definition
while @@fetch_status = 0
BEGIN
print 'CONSTRAINT: ' + @constraint_name
select @cmd = 'ALTER TABLE [' + @table_name + '] DROP CONSTRAINT [' + @constraint_name + ']'
print @cmd
EXEC sp_executeSQL @cmd;
fetch next from constraints into @table_name , @column_name, @constraint_name, @constraint_definition
END
close constraints
deallocate constraints