--去掉所有表约束
declare @n nvarchar(max)
declare allTable cursor for
select name from sys.tables
open allTable
fetch next from allTable into @n
while @@fetch_status = 0
begin
exec ('ALTER TABLE '+@n+' NOCHECK CONSTRAInT ALL')
exec ('ALTER TABLE '+@n+' DISABLE TRIGGER ALL')
print('已经去掉表'+@n+'的约束')
fetch next from allTable into @n
end
close allTable
deallocate allTable
--恢复所有表的约束
declare @n nvarchar(max)
declare allTable cursor for
select name from sys.tables
open allTable
fetch next from allTable into @n
while @@fetch_status = 0
begin
exec ('ALTER TABLE '+@n+' CHECK CONSTRAInT ALL')
exec ('ALTER TABLE '+@n+' enABLE TRIGGER ALL')
print('已经恢复表'+@n+'的约束')
fetch next from allTable into @n
end
close allTable
deallocate allTable