views:

517

answers:

3

If you include a NOLOCK on a select from a VIEW, does that NOLOCK propagate down into the tables joined within the view? If not, what's the purpose of locking a VIEW?

Sample View Code:

CREATE VIEW [my_custom_view]
AS
  SELECT
    a1.[column_a], a1.[column_b], a1.[column_c], a1.[column_d]
  FROM
    [table_a] a1
    JOIN [table_b] b1 ON b1.[column_a] = a1.[column_b]

And the NOLOCK statement:

SELECT 
  [column_a], [column_b]
FROM
  [my_custom_view] NOLOCK
+2  A: 

http://stackoverflow.com/questions/311429/using-with-nolock-table-hint-in-query-using-view-does-it-propagate-within-the-v

jinsungy
without going to the link the answer is "YES"
KM
You know, I searched and searched on SO for an answer like that before posting. Doh. Thank you.
eduncan911
+1  A: 

Why not just add nolock to the view definition? that way you don't need to explicitly add it to the view

Joel Martinez
Cause several views are dozens of tables deep, and quite complicated. (Off-shore development team) Not to mention over 50 of them.
eduncan911
+2  A: 

NOLOCK frequently causes incorrect results, Can you use snapshot isolation instead?

AlexKuznetsov