您的位置:首页 > 数据库

SQL SERVER 建临时表、循环插入数据、游标遍历数据库

2015-09-18 18:28 701 查看
create table #tmp (id int)  --建立临时数据表

declare @x int  --循环插入数据
set @x=1
while @x<=10
begin
insert into #tmp values(@x)
set @x=@x+1
end

--建立游标 遍历数据库
declare tmpCursor CURSOR for
select * from #tmp
open tmpCursor

declare @id int
fetch next from tmpCursor into @id

while  @@FETCH_STATUS =0
begin
print @id
fetch next from tmpCursor into @id
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: