declare @csname varchar(100)
set @csname=''
select @csname=[name] --约束名称
from sysobjects t
where id=(select cdefault from syscolumns where id=object_id(N'表名') and name='字段名')
--动态删掉约束
exec('alter table 表名 drop constraint '+@csname)
--动态禁用约束
exec ('alter table 表名 nocheck constraint ' + @csname)
--动态启用约束
exec ('alter table 表名 check constraint ' + @csname)
本文介绍了一种使用T-SQL动态地管理SQL Server中表约束的方法,包括删除、禁用及启用约束。通过定义变量存储约束名称,并利用动态SQL执行相关操作。
1250

被折叠的 条评论
为什么被折叠?



