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
SQL SERVER 建临时表、循环插入数据、游标遍历数据库
最新推荐文章于 2023-04-24 17:41:31 发布