Programming in MS SQL Server 2012

Open Cursor



Opens a Transact-SQL server cursor and populates the cursor by executing the Transact-SQL statement specified on the DECLARE CURSOR or SET cursor_variable statement.

The following example describes to open a declared cursor to start query execution.

-- Example 144 --

 

DECLARE EmployeeList CURSOR FOR

SELECT

   EMP.Emp_Code,

   EMP.Emp_Name,

   EMP.Salary,

   EMP.Dept_Code,

   DEPT.Dept_Name FROM EMP

INNER JOIN DEPT

ON EMP.Dept_Code = DEPT.Dept_Code

 

OPEN EmployeeList


Query Output Screen



Note:

If the cursor is declared with the INSENSITIVE or STATIC option, OPEN creates a temporary table to hold the result set. OPEN fails if the size of any row in the result set exceeds the maximum row size for Microsoft SQL Server tables. If the cursor is declared with the KEYSET option, OPEN creates a temporary table to hold the keyset. The temporary tables are stored in tempdb.

* * * * *


Email Your Comment To AUTHOR