Introduction
In this article I am explaining how to fetch records using a cursor in SQL Server 2012. A cursor in SQL serever 2012 is a database object that points to a result set. We use a cursor in SQL Server 2012 to retrieve a specific row or data from a result set.
There are two ways to implement a cursor in SQL Server 2012:
- Standard Database APIs : We can implement a cursor through standard database APIs.
- Through Transact-SQL : We can implement a cursor through Transact-SQL
Implementation of Cursor in SQL Server
To create a cursor we use various clauses. A DECLARE clause is used to define a new cursor, an OPEN clause is used to open the cursor and a FETCH clause is used to retrieve data from a result set. CLOSE is used to close a cursor. A DEALLOCATE clause is used to delete a cursor.
Types of cursors in SQL Server 2012:
- Dynamic cursor
- Keyset cursor
- Static cursor
- Forward-only cursor
- Forward-only KEYSET cursor
- Forward-only stataic cursor
- Fast_Forward cursor
Statement that creates a table
|
createtable mcninvoices |
Statement that inserts data into a table
|
insertinto mcninvoices values (20,'e001',100,100,0.00) |
Statement that shows all data of mcninvoicetable

Statement that creates the mcnvendors table in SQL Server 2012
|
createtable mcnvendors ( vendoridint, vendornamevarchar(15), vendorcityvarchar(15), vendorstatevarchar(15) ) |
Statements that insert data into the mcnvendors table in SQL Server 2012















gajraj singhPosted Dec 24, 2012, 8:07 AM
vvbb