在SQL Server 2008中的Keyset驱动游标

在本文中,将介绍SQL Server 2008中的KeySet驱动游标。

在KeySet-Drivin游标的帮助下,我们可以找到表的第一行,下一行,最后一行和任何特定行。

首先,我们创建一个名为EMP的表来,并此表上应用游标:

创建表

create table emp(emp_id int,em_name varchar(10))

go

insert into emp

select 1,'d' union all

select 2,'e' union all

select 3,'f' union all

select 4,'mahi' union all

select 5,'gill' union all

select 6,'singh'

go

select * from emp

keyset驱动游标:

它位于静态和动态游标之间。
当我们打开keyset-drivin游标时,它会保存整个结果集的唯一值列表,这些值称为KeySet。
这些键检索每行的当前数据值。

创建Keyset驱动游标:

declare key_cursor cursor

keyset for

select * from emp

打开Keyset驱动游标:

open key_cursor

从Keyset-Drivin游标获取第一行数据:

fetch firstfrom key_cursor

关闭Keyset驱动游标:

close key_cursor

删除keyset驱动游标:

deallocate key_cursor
日期:2020-06-02 22:18:02 来源:oir作者:oir