When using cursors in stored procedures in SQL Server, you need to be aware of the scope of the cursor and how it can be accessed within calling or called procedures. Cursors in SQL Server can be declared as local or global. A global cursor defined in a stored procedure is available until it is deallocated or when the connection closes. A local cursor goes out of scope when the stored procedure that declared it terminates or the procedure scope changes.
If neither the
LOCAL option is specified when the cursor is declared in a stored procedure, the default cursor type is determined by the database option
CURSOR_DEFAULT, which you set with the
ALTER DATABASE statement. The default value for the option ...