环境:
OS:Windows 2003
DB:SQL 20008
-- 创建备份表
select * into tb_test_bak from tb_test where 1=2;
-- 定义游标
declare cur_data cursor for select id,name from hxl.dbo.tb_test;
通过游标将数据备份到备份表
--打开游标
open cur_data
--申明变量接收游标取得值,游标读取的表有几个字段你就要申明几个变量去接收
declare @id varchar(50)
declare @name varchar(1000)
select @name = ''
--使用游标
fetch next from cur_data into @id,@name
while(@@fetch_status=0)
begin
insert into tb_test_bak values(@id,@name);
fetch next from cur_data into @id,@name
end
--关闭游标
close cur_data
--释放游标
deallocate cur_data
阅读(3417) | 评论(0) | 转发(0) |