My understanding is that when NOLOCK is used in SELECT statement, it could read uncommitted / dirty rows as well. But I wanted to take advantage of NOLOCK hint on table so that my SELECT query will run fast.
Now, does NOLOCK on table but along with "SET TRANSACTION ISOLATION LEVEL READ COMMITTED" give me NOLOCK advantage and faster SELECT query (because of NOLOCK) with only committed rows (because of SET)?
yes a table hint overrides the isolation level setting, so you will still get dirty reads
easy to test
first run this
create table bla(id int)
insert bla values(1)
begin tran
select * from bla with (updlock, holdlock)
make sure not commit the tran!! open another window and run this
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
select * from bla -- with (nolock)
you don't get anything back.
open another window and run this now
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
select * from bla with (nolock)
as you can see you will get back the row
BTW, READ COMMITTED is the default isolation level, no need to set it
Take a look at Snapshot Isolation which won't give you back dirty data but still won't lock
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With