Locking to be done in T-SQL

  • 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? I don't want to use NOLOCK.

    User2 should be able to see the record as it was before user 1 modified (basically before image)

    Thanks

    Murali S

  • >>How do we see the records? I don't want to use NOLOCK. <<

    [edit:] I thought that nolock  will let you do that but I was mistaken. It does not

    Why do you need that anyway?

     

     


    * Noel

  • I don't believe you can do that in Sql 2000.  However I think Sql Server 2005 will have a method to accomplish what you are asking.  For now you need to keep you uncommitted transactions as short as possible and do not allow any user intervention until the transaction is committed or rolled back.

     

  • He's a link to info on the snapshot isolation level in sql 2005.

    http://msdn.microsoft.com/sql/2005/2005articles/default.aspx?pull=/library/en-us/dnsql90/html/sql2k5snapshotisol.asp

     

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

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