One of my client session creates an entry in the table from a transaction and continues its processing. The transaction runs under the isolation mode read committed. Meanwhile, the other client session reports all data in the table.
The selecting all action is entirely locked now because of the locked row (inserted by other client).
How can I just retrieve the committed data during the select all, instead of getting completely locked?
Any help would be greatly appreciated.
You haven’t really been very specific about your usage scenario, but it is possible to get the data out of the table, there are just some severe caveats.
You can use the
READ UNCOMMITTEDsnapshot isolation level, as marc_s said, and that has the same effect as usingWITH (NOLOCK)on all of your select statements within the transaction. If you want to read just that table but treat all other reads in your transaction normally then you are better putting theNOLOCKhint on the specific table within the query. So, for example:That would issue a normal read lock for
firstTablebut readsecondTablewith no locks. No locks can be quite dangerous – as you can get effectively corrupt data out. If the insert being performed reorders data and causes a page split, you can get out the same row twice and all sorts of similar unpleasantness.So it is possible, but it’s not ideal, and you should be wary of the effect. Some good further reading is here, courtesy of Jason Strate.