SQL Server 临时禁用和启用所有外键约束(转)
--获得禁用所有外键约束的语句
select 'ALTER TABLE [' + b.name + '] NOCHECK CONSTRAINT ' + a.name +';'
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id
--获得启用所有外键约束的语句
select 'ALTER TABLE [' + b.name + '] CHECK CONSTRAINT ' + a.name +';'
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id