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 |
|
amruta488
Starting Member
1 Post |
Posted - 2012-01-06 : 02:23:52
|
| I have two query one is updating table and another is selecting information from table at a time.If you try first query in sql server Query1:begin tranupdate tAsset set UpdatedBy='admin'then fire below query Query2:begin transelect * from tAssetthen above query wait until update has lock on it.So, I have use as belowQuery3:begin transelect * from tAsset with(nolock)it works fine for me.I have problem in Query4 and Query5Query4:begin tranupdate tAsset set UpdatedBy='admin'Query5:begin tranupdate tAsset set UpdatedBy='admin'Query4 is execute but Query5 is wait until Query4 has release lock.How to handle this scenario in sql query? |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-01-06 : 06:46:09
|
quote: stuff.....How to handle this scenario in sql query?
In only the order I thought of them. Some are much more important than others:1) Don't hold transactions open any longer than you need to2) Make sure your operations are as fast as possible given other constraints (disk space / maintenence). This means good INDEXING.3) try a different ISOLATION LEVEL (try READ_COMMITTED_SNAPSHOT if on 2005 or better)4) Database design -- in a high throughput OLTP scenario then you want to be as normal as possible. Google NORMALISATION if that doesn't mean anything to you5) Multi Threaded application design (Locking / Actor model / whatever -- basically be smarted when issuing requests)6) ...7) ...8) ...9) ...Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-06 : 10:07:12
|
| 0) Optimise the queries and tune the indexes so that SQL can take minimal locks and hold them only for a very short time.--Gail ShawSQL Server MVP |
 |
|
|
|
|
|