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: these days I have AI do the annoying stuff for me. My new video course teaches you to work the same way, and I teach whole teams in a one-day workshop. Someone still has to know enough SQL Server to keep the robots in check, and that’s what my training is for.



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.