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)
 NOLOCK

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-01-16 : 23:19:16
Does adding the NOLOCK clause to queries always help?


ie. SELECT * FROM table (NOLOCK) ...


LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-01-16 : 23:35:18
Of course not. If it always helped, why would it be optional?
If you don't care about the integrity of your results it "helps" get that random data a bit faster.
Check out the row versioning stuff in 2005. Much more useful.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-16 : 23:38:30
If the database is read only then it couldn't hurt although it may not help every situation. No one will every block anyone else. For read-write databases you should just understand what NOLOCK does. It allows uncommitted transactions to be "read" (dirty reads). That could potentially lead to inaccurate results. I guess it depends on the type of business your database represents. For a CRM system it may not hurt to use dirty reads but in a financial system or reservation system it could really mess you up.

Be One with the Optimizer
TG
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-01-16 : 23:52:05
it can also cause your query to simply fail. see:

http://blogs.msdn.com/craigfr/archive/2007/06/12/query-failure-with-read-uncommitted.aspx


elsasoft.org
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-01-17 : 05:36:11
More fun with NOLOCK:
http://www.sqlmag.com/Articles/ArticleID/92888/92888.html?Ad=1
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-01-17 : 08:00:43
This is not a universal law - but generally , if the db system is looking at trends such as an OLAP it may not be as dangerous, whereas with an OLTP it's more risky. It depends on the situation.

I would first focus on indentifying slow queries , indexing etc and use NOLOCK as a last resort

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-01-17 : 09:15:35
yeah this is for a web application (to server content), and it is a mostly a read heavy, and writes are very low in the ratio compared to reads (and the data integrity is not really an issue like a i twould be for a bank etc.)
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-01-17 : 19:17:57
Seriously - try the row versioning.
Go to Top of Page
   

- Advertisement -