Create Proc
The cursor
will iterate and return its position each time, only once it returns 0 is it complete. Looping like this was useful if the resulting insert needed to trigger another proc.
READ_ONLY Prevents updates made through this cursor.
FORWARD_ONLY Specifies that the cursor can only move forward and be scrolled from the first to the last row. FETCH NEXT is the only supported fetch option.
LOCAL Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created.
STATIC Specifies that the cursor always displays the result set as it was when the cursor was first opened, and makes a temporary copy of the data to be used by the cursor
1 | CREATE OR ALTER PROCEDURE [dbo].[prc_run_some_crap] |
- https://github.com/carlpaton/SQLStatements/blob/master/mssql/General/stored-proc-with-cursor-loop.sql
- https://docs.microsoft.com/en-us/sql/t-sql/language-elements/declare-cursor-transact-sql?view=sql-server-ver15
Execute Proc
1 | EXEC dbo.[prc_run_some_crap] @id = 123, @second_param_id = 456; |