sql 代码
- 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
SQL批量禁用表约束
本文提供了一段SQL脚本,用于遍历数据库中的所有用户表,并通过动态执行SQL命令来临时关闭这些表上的所有约束,这对于进行大量数据操作前减少数据库负担非常有用。
81

被折叠的 条评论
为什么被折叠?



