Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Can NoLock be used on table-returning functions?


Can NoLock be used on table-returning functions?

Author
Message
nonghead-webspam
nonghead-webspam
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 135
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?
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3046 Visits: 5478
...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?

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
nonghead-webspam
nonghead-webspam
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 135
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.
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3046 Visits: 5478
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

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47388 Visits: 44399
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


nonghead-webspam
nonghead-webspam
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 135
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search