SQL Server 临时禁用和启用所有外键约束

--获得禁用所有外键约束的语句
select  'ALTER TABLE ['  + b.name +  '] NOCHECK CONSTRAINT ' +  a.name +';' as  禁用约束  
from  sysobjects  a ,sysobjects  b    
where  a.xtype ='f' and  a.parent_obj = b.id


--获得启用所有外键约束的语句
select  'ALTER TABLE [' + b.name +  '] CHECK CONSTRAINT ' +  a.name +';' as  启用约束    
from  sysobjects  a ,sysobjects  b    
where  a.xtype ='f' and  a.parent_obj = b.id

 

REF: http://topic.csdn.net/t/20030714/14/2025998.html

 

posted @ 2008-09-22 21:48  emanlee  阅读(5098)  评论(0编辑  收藏  举报