tags:

views:

126

answers:

2

In our company we tend to us views and store procedures.

We've recently started to implement the NOLOCK statement to alot of our views.

i was wondering if applying NOLOCK to a view, it "trickles down" to the store procedure...

Say i have a view call viewPartyPackage

and view statement was...

SELECT     PartyPackageID, Name, Created, LastModified, Deleted FROM        dbo.PartyPackage WITH (NOLOCK) WHERE     (Deleted = 0)

and also i had a store proc:

ALTER proc [dbo].[partypackage_Select](  @PartyPackageID bigint = null ) AS SELECT * FROM [viewPartyPackage] PartyPackage WHERE (@PartyPackageID is null or @PartyPackageID = [PartyPackageID])

would i lose the NOLOCK feature because im calling from a store proc and in turn would i need to put a (NOLOCK) on the store proc as well? or does the NOLOCK thats in the view come into play?

+1  A: 

The NOLOCK in the view will take effect no matter where the view is called from.

Fosco
How about the other way round? if the NOLOCK was on the store proc and the view didn't have the NOLOCK?
Mike
If you select from the view with NOLOCK in a stored procedure, it will use NOLOCK for that specific call... but it wouldn't magically make the view always use NOLOCK.
Fosco
+1  A: 

See the answers to this SO question. To quote:

See Table Hints in MSDN: "In SQL Server 2005, all lock hints are propagated to all the tables and views that are referenced in a view. Also, SQL Server performs the corresponding lock consistency checks."

Oded
sorry to repeat the question on this post. What about the other way round: if theres a NOLOCKon the store proc and the view didn't have the NOLOCK?
Mike
@Mike - stored procedures do not have NOLOCK defined. They may define NOLOCK on the tables/views they call.
Oded
thanks for your answers :D
Mike