Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Can NoLock be used on table-returning functions? Expand / Collapse
Author
Message
Posted Tuesday, July 1, 2014 9:09 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 8:54 AM
Points: 67, 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?

Post #1588078
Posted Tuesday, July 1, 2014 9:26 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 2,856, Visits: 5,125
...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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1588087
Posted Tuesday, July 1, 2014 9:35 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 8:54 AM
Points: 67, 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.
Post #1588090
Posted Tuesday, July 1, 2014 9:49 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 2,856, Visits: 5,125
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1588096
Posted Tuesday, July 1, 2014 10:24 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:25 PM
Points: 39,910, Visits: 36,250
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 2008, MVP
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

Post #1588119
Posted Tuesday, July 1, 2014 12:39 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 8:54 AM
Points: 67, 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.
Post #1588168
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse