This OVERPOWERED Hint Will Break NOLOCK Hints In SQL Server

G4M3R


CREATE TABLE
    dbo.view_me
(
    id int NOT NULL
);
GO 

CREATE VIEW 
    dbo.viewed
AS 
SELECT
    vm.*
FROM dbo.view_me AS vm WITH(READCOMMITTED);
GO 

SELECT
    v.*
FROM dbo.viewed AS v WITH(NOLOCK);
GO

Msg 4138, Level 16, State 1, Line 22

Conflicting locking hints are specified for table “dbo.view_me”. This may be caused by a conflicting hint specified for a view.

Thanks for reading!

Going Further


If this is the kind of SQL Server stuff you love learning about, you’ll love my training. Blog readers get 25% off the Everything Bundle — over 100 hours of performance tuning content. Need hands-on help? I offer consulting engagements from targeted investigations to ongoing retainers. Want a quick sanity check before committing to a full engagement? Schedule a call — no commitment required.



2 thoughts on “This OVERPOWERED Hint Will Break NOLOCK Hints In SQL Server

  1. what we need is ReadUNCommittedSnapshotIsolation (TM)
    So anything under a NOLOCK hint or ReadUncommitted uses snapshot isolation instead, I’m not holding my breath for that change from Microsoft though.
    Worked last year with a company whose developers still put NOLOCK on everything, I showed them they could get incorrect results and they just shrugged

Comments are closed.