Locking Isssues in Sql server 2000

  • Please help in this,

    I have a table called Test in that with 2 fields say F1,F2.

    The values may be like this:

    A,Apple

    C,Cat

    E,Elephant.

    In Query analyser, We have two connection say User1 and User2.

    User1 going to modifys the record Apple to Ant with the following statement

    BEGIN TRAN

    UPDATE Test SET F2 = 'Ant' WHERE F1 = 'A'

    and he is not committed.

    At the same time, user2 wants to see the records with the following statemens:

    BEGIN TRAN

    SELECT * FROM Test

    My question is:

    User1 is running the above statement and it returing 1 row affected. But in User2 we are not able to see the any records itself.

    How do we see the records? and i need to know how the sqlserver 2000 is locking the records?

    Thanks

    Murali S

  • Hi,

    In the statement where you do the update, execute COMMIT TRAN

    after the update statement, this will actually commit the transaction and close the open transaction.

    BEGIN TRAN

    UPDATE Test SET F2 = 'Ant' WHERE F1 = 'A'

    COMMIT TRAN

    After this if you a select, you should be able to see the records.

    For locking info, use the system stored porocedure sp_who2 or sp_lock.

    Hope this helps.

  • While updating use hint: with (ROWLOCK)

    e.g.

    UPDATE Test with (ROWLOCK) SET F2 = 'Ant' WHERE F1 = 'A'

    Regards,

    Salman

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

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