Wednesday, March 7, 2012

NOLOCK hint on views?

Hi all

If i have a view:

CREATE VIEW vw_Users

AS

SELECT * FROM Users WITH(NOLOCK)

Is it suggested to use nolock in views?

And if i needed to use this view in stored procs is it then suggested to apply the nolock hint?

CREATE PROC [dbo] .[usp_GetCompanyUsers]

AS

SELECT * FROM Companies WITH(NOLOCK) JOIN

vw_Users WITH(NOLOCK) --<< --is this suggested?

If you using NOLOCK hint while creating view, you don't need to use the NOLOCK again when accessing the view. The locking is always done on the table and not on the view.

No comments:

Post a Comment