停用外键约束删除数据
select
'ALTER TABLE '+o.name+' NOCHECK CONSTRAINT '+fk.name+';' AS Command
from
sys.foreign_keys fk
JOIN sys.all_objects o ON (fk.parent_object_id=o.object_id)
复制结果, 粘贴出来执行. 就停用 外键约束了.
然后你去删除数据去.
数据删除好了, 再启用外键约束
select
'ALTER TABLE ' + o.name + ' CHECK CONSTRAINT ' + fk.name + ';' AS Command
from
sys.foreign_keys fk
JOIN sys.all_objects o ON (fk.parent_object_id = o.object_id)