Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to handle Locking.

Author  Topic 

sql_2k
Starting Member

26 Posts

Posted - 2008-05-07 : 14:36:38
Hi All,

Please help me out how to implement the locking in below scenario

Req -

There are two tables Table1 & Table2
If I will insert in table1 then related data fields will be auto updated in table2 , similarly based on the data in table2 table1 data needs to be updated.

Now the sync of table1 & table2 is working fine.

My prob is we are handling the updation/insertion from the UI screens . Two separate screen for each table. When we have multiple user accessing the screens say - User1 updates table1 and User2 updates table2 then we need to implement the locking so that at one time one screen will allow updation in the table1 and hence table2.
The other screen shouldnt allow updation in table2 and hence in table1.

This is very common locking functionality ...but am not getting any way to implement it , Please advise.

Srain.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-07 : 16:04:05
Should sql handle that automatically? You may get deadlock if enforce with tablock hint.
Go to Top of Page

sql_2k
Starting Member

26 Posts

Posted - 2008-05-07 : 21:54:18

SQl should handle such scenarios but I am afraid if the transaction by users at the same time might cause the data inconsistency..

SO in the application level we should not allow the multiple user to update at the same time.

In my case if one user inserts/updates table1 then other user shuouldnt be allowed to do any insertion/updation in table2 from the screen.


Can we use Timestamp to handle concurrency on updates against multiple tables and succeed in making any change only if ALL the timestamp values are a match.

Please share your thoughts.

Thnaks,
Srain.




quote:
Originally posted by rmiao

Should sql handle that automatically? You may get deadlock if enforce with tablock hint.

Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-07 : 22:17:42
No, sql will not let you update same row (page or table, depends on lock level) at same time.
Go to Top of Page
   

- Advertisement -