Fetching Records using Keyset-driven Cursor in SQL Server 2008

In this article I describe how to fetch first, next, last, or any specific row with the help of keyset-driven cursor.
  • 2463

Introduction

In my previous article I describe about keyset-driven cursor. Now in this article I describe how to fetch first, next, prior, last, or any relative row with the help of keyset-driven cursor.

Fetching data using keyset-driven Cursor:

Opening of keyset-driven Cursor:

We open a keyset-driven cursor as in the in following:

open key_cursor

Fetching the first data using keyset-driven Cursor:

fetch First from key_cursor

Output:

Keyset-driven-cursor-in-sql-server-first1.jpg

Fetching next data using keyset-driven Cursor:

fetch next from key_cursor

Output:

Keyset-driven-cursor-in-sql-server-next.jpg

Fetching previous data using keyset-driven Cursor:

fetch prior from key_cursor

Output:

Keyset-driven-cursor-in-sql-server-prior.jpg

Fetching next 2nd data using keyset-driven Cursor:

fetch relative 2 from key_cursor

Output:

Keyset-driven-cursor-in-sql-server-relative.jpg

Fetching last data using keyset-driven Cursor:

fetch last from key_cursor

Output:

Keyset-driven-cursor-in-sql-server-last.jpg

Closing and Deallocating the keyset-driven Cursor:

We close and deallocate Dynamic Cursor as in the following:

close key_cursor
deallocate key_cursor

© 2020 DotNetHeaven. All rights reserved.