Table Locks in Cursors

  • I (User A) have a cursor in which i am selecting records from a table A. While this cursor is getting executed, someone else (user B) is trying

    to read/write data from the same table A. Will the cursor lock the table and not allow user B to read/write from table A?

    Do i need to write cursor in some unique way so that user B can access Table A while user A is performing cursor operations on Table A?

    Thanks,

    Ramesh.

  • Declare the cursor LOCAL FORWARD_ONLY STATIC READ_ONLY if thats all User A needs - refer to DELCARE CURSOR options in BOL - http://technet.microsoft.com/en-us/library/ms180169.aspx

  • Yes... you need to write it in a "special" way... without a cursor! 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I second Jeff - rewrite the code to not use a cursor at all. Failing this, wouldn't a FAST_FORWARD cursor be best with NOLOCKs in the SELECT?

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

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

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