I understand the approach of Uri immediately returning the error code
to the caller.
However the short answer "Yes" from Roy does not seem to be correct.
So I did a test script by myself to understand it: sp1 calls sp2, sp2 calls
sp3. Each sp does an INSERT INTO Testtabelle1.
sp3 causes a constraint violation by an INSERT command. But all other INSERTs
remain in spite of a Transaction surrounding all the code in sp1. The @@ERROR
of sp3 is "too far away" from sp1.
>>>>>
use pubs
GO
ALTER PROCEDURE sp1
AS
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Testtabelle1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Testtabelle1]
CREATE TABLE [dbo].[Testtabelle1] (
[pk] [int] IDENTITY (1, 1) NOT NULL ,
[name] [char] (10) COLLATE Latin1_General_CI_AS NOT NULL
) ON [PRIMARY]
BEGIN transaction t1
INSERT INTO testtabelle1
(name)
VALUES
('von_sp1')
EXECUTE sp2
IF @@ERROR <> 0
BEGIN
/* print 'rollback' */
ROLLBACK transaction t1
END
ELSE
BEGIN
/* print 'commit' */
COMMIT transaction t1
END
GO
ALTER PROCEDURE sp2
AS
INSERT INTO testtabelle1
(name)
VALUES
('von_sp2') -- ok
execute sp3
GO
ALTER PROCEDURE sp3
AS
INSERT INTO testtabelle1
(name)
VALUES
(NULL) -- violation
INSERT INTO testtabelle1
(name)
VALUES
('von_sp3')
GO
<<<<<
Joachim
>> Stay informed about: Transactions in general