Results 1 to 8 of 8

Thread: Will a cursor fetch lock the table

  1. #1
    Join Date
    Sep 2003
    Posts
    5

    Will a cursor fetch lock the table

    Open a cursor , Fetch the record ,
    during this kind of operation , will the specific table be locked and fail
    to be updated or select by another session ?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Depends on the type of cursor created. At the minimum the row you are fetching is shared locked during select.

  3. #3
    Join Date
    Sep 2003
    Posts
    5
    I think shared lock will not affect
    any updation or selection triggered by another session ?

  4. #4
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    shared lock will block update but not select. Because update requires an exclusive lock.

  5. #5
    Join Date
    Sep 2003
    Posts
    5
    Do you mean that while fetching a record in the cursor , the specific row will locked and the updation will be failed or have to wait !

    it surprise me ! because this never happens in oracle !

  6. #6
    Join Date
    Sep 2002
    Posts
    5,938
    You can add nolock hint in your select statement.

  7. #7
    Join Date
    Mar 2003
    Location
    Woking, UK
    Posts
    152
    NOLOCK hint shows all data also uncommited. Oracle shows only commited. So in MSSQL you can use READPAST hint to read only commited transaction.
    You Have To Be Happy With What You Have To Be Happy With (KC)

  8. #8
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Yes it is not same as Oracle, update is blocked by select for the duration of select.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •