What is Cursor in SQL Server? Cursor can be seen as a way to implement looping to SQL , which isn't a programming language, so much so it is a transactional language. SQL Cursor Life Cycle The following steps are involved in a SQL cursor life cycle. 1. Declaring Cursor At this stage, we define the SQL statement for the cursor, in turn defining the data set on which we are supposed to loop. 2. Opening Cursor Once we know the dataset, it's time to actually fetch that dataset for our cursor to run through. 3. Fetching Cursor This is the main step which is being looped over, in a sense. It fetches one row at a time from our cursor so that operations can be performed on the data fetched. 4. Closing Cursor The cursor should be closed explicitly after data manipulation. 5. Deallocating Cursor Cursors should be deallocated to delete cursor definition and release all the system resources associated with the cursor. In upcoming blog we will have an example on CURSOR.
Comments
Post a Comment