SQL Cursors and It’s Use In VB.NET 7th July 2016
In this blog from CRB Tech Reviews, we will see in detail the concept of SQL cursors and it’s use in VB.NET. Cursor Definition: Cursor is basically a database object used to recover data from a result set line by line, rather than the TSQL commands that work on every one of the rows in the result set at one time. We utilize cursor when we have to update records in a database table in singleton style implies line by line. Now we will see the basic syntax of a cursor: DECLARE cursor_name CURSOR [LOCAL | GLOBAL] –scope of cursor is defined over here. [FORWARD_ONLY | SCROLL] – the direction of cursor movement is defined in this line (forward/backward) [STATIC | KEYSET | DYNAMIC | FAST_FORWARD] – basic type of cursor is declared over here. [READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] – define locks FOR select_statement – SQL Select statement is mentioned FOR UPDATE [col1,col2,...coln] – names of columns that need to be updated are passed here as parameters. This is the syntax to define a SQL cursor. Declare Cursor SQL Comaand is utilized to define the cursor with numerous alternatives that affect the scalability and loading conduct of the cursor. Cursor Life Cycle: 1. Cursor Declaration: For declaring a cursor, one needs to define a SQL statement which returns a result set.