领导说让我清空大部分表,那就清呗。
truncate table 变量竟然不行。。
额,那就生成语句吧。。。
declare @table varchar(100)
declare cur cursor--定义一个游标
read_only
for select sysobjects.name as name from syscolumns,sysobjects,systypes where syscolumns.id=
sysobjects.id and syscolumns.xtype=systypes.xtype and sysobjects.type='U' and systypes.name <>'_default_'
and systypes.name<>'sysname' group by sysobjects.name HAVING sysobjects.name LIKE 'A0%' AND
sysobjects.name NOT LIKE '%A002' AND sysobjects.name <>'A005a001'
order by sysobjects.name --为所获得的数据集指定游标
open cur--打开游标
fetch next from cur into @table--把提取操作的列数据放到局部变量中
while(@@fetch_status=0)--返回被 FETCH 语句执行的最后游标的状态,而不是任何当前被连接打开的游标的状态。
begin
PRINT 'TRUNCATE TABLE '+@table--执行操作
--提前下一位信息
fetch next from cur into @table
end
close cur--关闭游标
deallocate cur--删除游标
go