Microsoft SQL Server Cursors

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ]
    • [ FORWARD_ONLY | SCROLL ]
      [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
      [ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
      [ TYPE_WARNING ]
    • FOR select_statement
    • [ FOR UPDATE [ OF column_name [ ,...n ] ] ]

Remarks

Normally you would want to avoid using cursors as they can have negative impacts on performance. However in some special cases you may need to loop through your data record by record and perform some action.



Got any Microsoft SQL Server Question?