Pawan Nogariya
Pawan Nogariya

Reputation: 8950

Inserting new rows to the table used for cursor, inside the cursor

I am looping through the rows of a temporary table using cursor and inside the cursor I am inserting new rows to the same table used for cursor.

What behaviour I have noticed is that the cursor doesn't include new rows that gets added within the cursor. For my requirement this is what I wanted but I am not sure the behavior I am noticing is correct because my query is complex and I don't know if it can fail later if my observation of the behaviour is wrong.

So doesn't cursor consider rows of the table that was added later inside the cursor?

Upvotes: 2

Views: 824

Answers (1)

PSK
PSK

Reputation: 17943

All static cursors takes a snapshot of the data into tempdb, any change in the underlying data will not impact the change.

If you want the impact to appear, you can use dynamic cursor in SQL Server.

You can read more on dynamic cursor here and here

Upvotes: 1

Related Questions