July 1, 2014 at 9:09 am
I'm trying to use NoLock in my code, and it keeps barking back at me.
I the code uses table returning functions except down at the very bottom level.
Must NoLock be used only on a query selecting from a table, or can it be on a table-returning function?
July 1, 2014 at 9:26 am
...Must NoLock be used only on a query selecting from a table, or can it be on a table-returning function?
You better not to use NoLock at all.
What is your reason behind using it? What are you trying to achieve?
July 1, 2014 at 9:35 am
Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.
This is on a reporting database, not a transactional database, though there are datadumps on a daily basis, pulling fresh data in. but only at prescribed times, not all day long.
July 1, 2014 at 9:49 am
nonghead-webspam (7/1/2014)
Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.This is on a reporting database, not a transactional database, though there are datadumps on a daily basis, pulling fresh data in. but only at prescribed times, not all day long.
I wonder where did you found this instructions from. You should stick it to the closest rubbish bin you can find.
NoLock is not the method to improve the query performance - it is a road to return really dirty data. It may not return data which exists in a table, and it may return data which is not already there...
It has nothing to do what type of database you are working on.
If you investigate and "google" :-), you will find a lot of material on this subject. One of the MSDN one which I recommend to read first:
http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
July 1, 2014 at 10:24 am
nonghead-webspam (7/1/2014)
Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.
No.
Nolock is not a performance tuning technique. It's not there to make your queries faster and, if you have a DB that's static, it's going to have just about no effect.
Rather learn to tune your queries properly than flailing around randomly looking for a magic silver bullet that doesn't exist.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 1, 2014 at 12:39 pm
Thank you both for your prickly, opinionated responses, which......uh.....were right on the money, and I followed your advice and solved the problem another way.
Thanks, sincerely.
BTW, the answer to my question seems to be that "with (NoLock)" must be applied at the table level, and doesn't work with table returning functions.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply