22,210
社区成员
发帖
与我相关
我的任务
分享
declare @s varchar(1000)
declare cur cursor for select name from sysobjects where xtype = 'U'
open cur
fetch cur into @s
while @@fetch_status = 0
begin
exec('select * into '+@s+'_temp from '+@s)--这里的是@s+_temp
exec('truncate table '+@s)
exec('insert into '+@s+' select * from '+@s)--这里怎么又是@s,有点迷糊,错了?
fetch cur into @s
end
close cur
DEALLOCATE cur
declare @s varchar(1000)
declare cur cursor for select name from sysobjects where xtype = 'U'
open cur
fetch cur into @s
while @@fetch_status = 0
begin
exec('select * into '+@s+'_temp from '+@s)
exec('truncate table '+@s)
exec('insert into '+@s+' select * from '+@s)
fetch cur into @s
end
close cur
DEALLOCATE cur