--得到所有的表名 declare @sql varchar(8000) select 'DELETE FROM ' + NAME FROM SYSOBJECTS WHERE XTYPE='U' AND NAME LIKE 'TMP_%' --这样可以一下得出所有要删除的语句 如何执行啊 准备做成JOB 自动来删除
[解决办法] --得到所有的表名 declare @sql varchar(8000) set @sql ='' select @sql+= 'DELETE FROM ' + NAME +' ' + char(13) FROM SYSOBJECTS WHERE XTYPE='U' AND NAME LIKE 'TMP_%' --这样可以一下得出所有要删除的语句 如何执行啊 准备做成JOB 自动来删除 print (@sql)
这条语句可以把SQL拼出来如果没问题你就Exec (@sql)就可以了 [解决办法]
DECLARE @sql VARCHAR(MAX) = '' SELECT @sql = @sql + 'DELETE FROM ' + NAME + CHAR(10) FROM SYS.TABLES PRINT @sql EXEC(@sql)
[解决办法] DECLARE @sql VARCHAR(MAX) = '' SELECT @sql = @sql + 'DELETE FROM ' + NAME + CHAR(10) FROM SYS.TABLES WHERE CHARINDEX('tmp',NAME) > 0 PRINT @sql EXEC(@sql) [解决办法] try this,
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