恢复和去掉所有表约束

--去掉所有表约束
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

 

 

posted @ 2014-03-19 19:42  二师弟tl  阅读(330)  评论(0编辑  收藏  举报