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