Last active
December 25, 2015 18:39
-
-
Save astannard/7022405 to your computer and use it in GitHub Desktop.
T-SQL Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @Id int | |
DECLARE TableCursor CURSOR LOCAL FAST_FORWARD FOR | |
SELECT Id | |
FROM dbo.TABLENAME | |
OPEN TableCursor | |
FETCH NEXT FROM TableCursor INTO @Id | |
WHILE @@FETCH_STATUS=0 | |
BEGIN | |
DO STUFF | |
FETCH NEXT FROM TableCursor INTO @Id | |
END | |
CLOSE TableCursor | |
DEALLOCATE TableCursor | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Optimized to be specific to the connection and the cursor is optimized for in order traversal