摘要:
declare @tab varchar(50),@forkey varchar(50),@sql varchar(200),@int int,@i intselect @int=count(*) from sys.foreign_keysset @i=1while @i <= @intbeginselect top 1 @tab=o.name,@forkey=fk.name from sys.foreign_keys fk JOIN sys.all_objects o ON (fk.parent_object_id=o.object_id)order by o.nameset @sql 阅读全文
摘要:
select 'ALTER TABLE '+o.name+' NOCHECK CONSTRAINT '+fk.name+';' AS Commandfrom sys.foreign_keys fk JOIN sys.all_objects o ON (fk.parent_object_id=o.object_id)具体会有多少条记录,取决于你的数据库里面,有多少个外键了。然后复制结果, 粘贴出来执行. 就停用 外键约束了.然后你去删除数据去.数据删除好了, 再启用外键约束select 'ALTER TABLE ' + o.name 阅读全文