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)
 Select statement with (NOLock)

Author  Topic 

yhchan2005
Starting Member

26 Posts

Posted - 2010-10-14 : 22:49:36
Refer to below SQL script

Select Field1, Field2,
( Select Field99 from Table3 with (NoLock)
Where .... ) Field3

from Table1 with (NOLock)
Inner Join Table2 with (NoLock) ON.....
Where ......

Do we need to put in the (NoLock) for subquery and inner join / left jon
if we have put in the (Nolock) in main query ????

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-14 : 23:55:47
Why are you even using the nolock hint in the first place? Why not instead use READ_COMMITTED_SNAPSHOT?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-10-15 : 03:00:16
NOLOCK means you will get the same record repeated twice in the resultset; some rows will not appear at all; plus you will get data included which is subsequently rolled back, or further modified by a trigger.

These things will happen very infrequently, and be extremely difficult to recreate in a DEV / TEST / QA environment; if the data is used for business decisions it may have catastrophic consequences for the business.

If all that is OK (for example, we ONLY use NOLOCK for DBAs to interrogate LOG tables that are being heavily written to) then fine. If not then don't use it!

As Tara says READ_COMMITTED_SNAPSHOT is probably what you need, particularly if you have READS blocking WRITES.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-10-15 : 04:31:19
Is inconsistent and possibly incorrect data acceptable?

See - [url]http://sqlblog.com/blogs/andrew_kelly/archive/2009/04/10/how-dirty-are-your-reads.aspx[/url]

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -