日期:2014-05-17 浏览次数:20485 次
--得到所有的表名
declare @sql varchar(8000)
select 'DELETE FROM ' + NAME FROM SYSOBJECTS WHERE XTYPE='U' AND NAME LIKE 'TMP_%'
--这样可以一下得出所有要删除的语句 如何执行啊 准备做成JOB 自动来删除
DECLARE @sql VARCHAR(MAX) = ''
SELECT @sql = @sql + 'DELETE FROM ' + NAME + CHAR(10) FROM SYS.TABLES
PRINT @sql
EXEC(@sql)
declare @tsql varchar(6000),@tabname varchar(200)
declare ap scroll cursor for
select name from sys.tables where name like 'tmp[_]%'
open ap
fetch first from ap into @tabname
while(@@fetch_status<>-1)
begin
select @tsql='truncate table '+@tabname
exec(@tsql)
fetch next from ap into @tabname
end
close ap
deallocate ap