--去掉所有表约束 declare @n nvarchar(max) declare allTable cursor for select name from sys.tablesopen allTable fetch next from allTable into @nwhile @@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 endclose allTabledeallocate allTable
--恢复所有表的约束 declare @n nvarchar(max) declare allTable cursor for select name from sys.tablesopen allTable fetch next from allTable into @nwhile @@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 endclose allTabledeallocate allTable