When ANSI_WARNINGS are ON and an insert fails due to permissions being denied, a transaction continues.
When ANSI_WARNINGS are OFF and an insert fails due to permissions being denied, a transaction is aborted.
In all my reading of the ANSI_WARNINGS documentation, I don't see anything that describes this behavior. Could someone please explain this?
Code to reproduce:
--------do this as sa--------- CREATE TABLE Junk( Name varchar(12) ) INSERT INTO Junk(Name) VALUES ('original') DENY INSERT ON Junk to dbUser --------------------------------- ---now do this as dbUser (update is not attempted)--- SET ANSI_WARNINGS OFF BEGIN TRAN INSERT INTO Junk(Name) VALUES ('new') update Junk SET Name = 'updated' where Name = 'original'
COMMIT TRAN -------------------------------- ---again as dbUser, do this (update is done)---- SET ANSI_WARNINGS ON BEGIN TRAN INSERT INTO Junk(Name) VALUES ('new') update Junk SET Name = 'updated' where Name = 'original'
COMMIT TRAN -----------------------------