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.
Author |
Topic |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-11-24 : 11:53:59
|
I've table as follow,tRunNoPref | RYear | RMonth | RunNo---------------------------------------_T | 2009 | 11 | 112_T | 2009 | 10 | 3890My logic as follow,1. If Pref='_T' and RYear='2009' and RMonth='11' EXIST in tRunNo, just update RunNo to RunNo+12. If Pref='_T' and RYear='2009' and RMonth='11' NOT EXIST in tRunNo, perform Insert into tRunNo values('_T','2009','11',1)I'm thinking of select statement will acquire a shared locks on the table using serializable transactionSo, my T-SQL as follow,if exists (select * from tRunNo with (updlock,serializable) where Pref='_T' and RYear='2009' and RMonth='11') begin update tRunNo set RunNo = RunNo+1 where Pref='_T' and RYear='2009' and RMonth='11' endelsebegin insert tRunNo (Pref,RYear,RMonth,RunNo) values ('_T','2009','11' 1)endDid my T-SQL will execute without any problem if multiple threads come? If yes, did this T-SQL is the best?Need technical answer |
|
|
|
|
|
|