1 declare testcur cursor scroll for 2 select top 10 newid() from [master].[sys].[databases] order by newid() 3 open testcur 4 5 print ('总行数'+CHAR(13)+CHAR(10)+convert(varchar(50),@@cursor_rows)) 6 7 declare @gid uniqueidentifier 8 9 FETCH LAST FROM testcur into @gid 10 print ('最后行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 11 12 FETCH PRIOR FROM testcur into @gid 13 print ('上一行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 14 15 FETCH ABSOLUTE 3 FROM testcur into @gid 16 print ('第三行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 17 18 FETCH RELATIVE 3 FROM testcur into @gid 19 print ('隔三行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 20 21 FETCH FIRST FROM testcur into @gid 22 print ('第一行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 23 24 while @@fetch_status=0 25 begin 26 FETCH NEXT FROM testcur into @gid 27 print ('下一行'+CHAR(13)+CHAR(10)+convert(varchar(50),@gid)) 28 end 29 30 close testcur 31 deallocate testcur