将所有用户表数据存入临时表后TRUN该表再将原数据导回的问题

fuxiaoyang13 2009-06-19 05:30:44
我想将某数据库里所有的用户表进行如下操作;先将某用户表中的数据先保存到一个临时表中后再将该用户表TRUNCATE后 再将保存出去的数据再导回原表,请问该如何做最好?
...全文
53 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuxiaoyang13 2009-06-23
  • 打赏
  • 举报
回复
没人啊???
fuxiaoyang13 2009-06-22
  • 打赏
  • 举报
回复
咋没人顶啊?
fuxiaoyang13 2009-06-20
  • 打赏
  • 举报
回复
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
我是这样做的啊,可做完后我发现,有些表的数据没有导回去,不知道是 啥原因
l1ka1lz8 2009-06-20
  • 打赏
  • 举报
回复
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

学习!
--小F-- 2009-06-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
SQL codedeclare @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
[/Quote]

学习
ai_li7758521 2009-06-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
SQL codedeclare @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
[/Quote]。
-狙击手- 2009-06-19
  • 打赏
  • 举报
回复
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

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧