本文共 642 字,大约阅读时间需要 2 分钟。
-- 方法1:游标-- 声明变量DECLARE @name AS NVARCHAR(100), @count as int set @count=0 -- 声明游标DECLARE C_Employees CURSOR FAST_FORWARD FOR select name from sysobjects where name in(select t.namefrom sys.tables as t, sysindexes as iwhere t.object_id = i.id and i.indid <=1 and i.rows=0 ) OPEN C_Employees;-- 取第一条记录FETCH NEXT FROM C_Employees INTO @name;WHILE @@FETCH_STATUS=0BEGIN -- 操作 print '准备'+@name exec ('drop table '+@name); set @count+=1; print '成功删除'+@name -- 取下一条记录 FETCH NEXT FROM C_Employees INTO @name;END -- 关闭游标CLOSE C_Employees;-- 释放游标DEALLOCATE C_Employees;print '共删除'+cast(@count as varchar(100)) +'个表'
转载地址:http://ethbb.baihongyu.com/