Complex query using cursors

  • I have a stored procedure with complex query which is using cursors. I know cursors are not good but now I cannot ask developers to change the code as I said the code is too complicated.

    Is there a way to debug how the cursor is working or how many times each cursor is fetching the data and what code it is processing?

    I tried using profiler, but I am confused of what events to use?

    Any help is greatly appreciated.

    Thanks

  • Hi,

    The Cursors is not always bad, in there is no Option to using other method, that time the programmers uses the Cursors.

    And you need to know the no of records the cursors fetches, for this the profiler is not required and not capture this information, because this is dynamic depends on the parameters you passed to the procedures.

    And you also refer this link to know more.

    http://www.sqlservercentral.com/articles/books/65797/

  • Can you show us the code?

  • Sometimes a cursor is the best solution. Not usually the fastest - but then that's not always the primary consideration.

    Aside from Profiler, there is a dynamic management view that you can look at to see information about currently open cursors:

    sys.dm_exec_cursors

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply