sqlservice禁用启用外键

来源:互联网 发布:帝国cms 阿帕奇伪静态 编辑:程序博客网 时间:2024/05/16 14:36
DECLARE @nocheckSql NVARCHAR(max)--禁用外键约束的sql  
 
SET @nocheckSql =   
(SELECT 'alter table dbo.['+b.name+'] nocheck constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')  
)  
print @nocheckSql  
--execute sp_executesql @nocheckSql  
 
DECLARE @checkSql NVARCHAR(max)--启用外键约束的sql  
 
SET @checkSql =   
(SELECT 'alter table dbo.['+b.name+'] check constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')  
)  
print @checkSql
0 0
原创粉丝点击