MSSQL_关闭\打开约束

来源:互联网 发布:去眼袋眼霜 知乎 编辑:程序博客网 时间:2024/05/29 02:47
declare @tbname varchar(250)   declare #tb cursor for select name from sysobjects where objectproperty(id,'IsUserTable')=1   open #tb   fetch next from #tb into @tbname   while @@fetch_status=0   begin    exec('alter table ['+@tbname+'] nocheck constraint all')      -- nocheck关闭所有约束 check开启所有约束     fetch next from #tb into @tbname   end  close #tb   deallocate #tb