---------暂停外键约束
declare @Sql nvarchar(200);
declare mycursor cursor for (select 'ALTER TABLE [' + b.name + '] NOCHECK CONSTRAINT ' + a.name +';'
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id)
open mycursor
fetch next from mycursor into @Sql
while(@@fetch_status = 0)
begin
exec(@Sql)
fetch next from mycursor into @Sql;
end
close mycursor
deallocate mycursor
---------启动外键约束
declare @Sql nvarchar(200);
declare mycursor cursor for (select 'ALTER TABLE [' + b.name + '] CHECK CONSTRAINT ' + a.name +';'
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id)
open mycursor
fetch next from mycursor into @Sql
while(@@fetch_status = 0)
begin
exec(@Sql)
fetch next from mycursor into @Sql;
end
close mycursor
deallocate mycursor
游标暂停和启用外键约束foreignkey
最新推荐文章于 2024-09-09 23:37:05 发布