How Many Types of Cursor in SQL
In this article I am going to explain how many types of cursor in SQL.
Introduction
A cursor is a database object that points to a result set. We use cursor to fetch any specific row from result set. Most of time cursor is used by application programmer.
Implementation of cursor in SQL
- We can implement cursor through standard database APIs.
- We can implement cursor through Transact-SQL
SQL Statement used in cursor
- DECLARE : It is used to define a new cursor.
- OPEN : It is used to open a cursor
- FETCH : It is used to retrieve a row from a cursor.
- CLOSE : It is used to close a cursor.
- DEALLOCATE : It is used to delete a cursor and releases all resources used by cursor.
There are four type of cursor
- Dynamic cursor
- Keyset cursor
- Static cursor
- Forward-only cursor
Dynamic Cursor
Dynamic cursor is scrollable and sensitive to database changes.
Keyset_cursor
Keyset_cursor is scrollable and sensitive to database changes for update and delete but not for insertion.
Static cursor
Static cursor is scrollable but not sensitive to database changes.
Forward_only
Forward_only is not scrollable but sensitive to database changes.