More on Cursors in T-SQL …

… As a continuation of my occassional slam on T-SQL cursors, I want you to take just a few minutes to read this blog post by the great Paul Randal. It is brief, but includes screen shots from the execution plans that shows more odd T-SQL cursor behavior. Because he used a dynamic optimistic cursor type, he kept getting keylookups in his query plans, despite the fact that he has indexes on the fields in his queries. This is because the cursor is maintaing a worktable in TempDB that it is using lookups against. This is a very good example of why using sets in T-SQL is much preferable than relying on cursors.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s