数据库用的时间长了,想删除产生的临时表,表太多,一个个删除太麻烦,建个游标,批量删除
执行脚本前,选择对应的数据库
也可以先执行下查询SELECT name FROM sysobjects WHERE TYPE='U' AND name LIKE 'tmpgoodsplu%';
看看要删除的表是不是对。
DECLARE @Table NVARCHAR(30)
DECLARE tmpCur CURSOR FOR
SELECT name FROM sysobjects WHERE TYPE='U' AND name LIKE 'tmpgoodsplu%'
OPEN tmpCur
FETCH NEXT FROM tmpCur INTO @Table
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @sql VARCHAR(100)
SELECT @sql = 'drop table ' + @Table
EXEC(@sql)
FETCH NEXT FROM tmpCur INTO @Table
END
CLOSE tmpCur
DEALLOCATE tmpCur