您的位置:首页 > 其它

恢复和去掉所有表约束

2014-03-19 19:42 211 查看
--去掉所有表约束
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: