我要将数据库中所有表名为tmp_开头的表 一次全都删除内容
例如tmp_aaa
tmp_bbb
tmp_ccc
tmp_...
DELETE FROM TMP_AA
一次性循环处理
------解决方案--------------------
while也是循环,但是while每次循环可以是一个数据集,而游标只有一行,万不得已可以尝试改成while。对于嵌套类型的循环,首先建议使用CTE。
对于你这个。貌似不需要做循环把?从sys.tables那里一次找出表名然后动态拼接成delete 语句就可以拉
------解决方案--------------------
- SQL code
declare @sql nvarchar(2000)set @sql=''select @[email protected]+ ' delete from '+ name from sys.sysobjects where name like 'temp%'print @sqlexec (@sql)
------解决方案--------------------
顶楼上!
------解决方案--------------------
while 的循环性能不如游标
无论那种都慢
能不循环尽量不要用循环
------解决方案--------------------
DELETE 太慢了,用truncate来清除数据
- SQL code
declare @sql varchar(max)set @sql=''select @[email protected]+'truncate table '+name+';' from sys.tables where name like '%temp'exec(@sql)