go
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('drop table ['+@tbname+']')
fetch next from #tb into @tbname
end
close #tb
deallocate #tb

本文介绍了一段SQL脚本,用于自动遍历并删除系统中的所有用户表。脚本通过声明变量、打开游标、执行循环操作、关闭游标和释放资源等步骤实现自动化表删除功能。

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



