Hi!
I have the following problem. I have to stored procedures (debug messages double-indended):
CREATE PROC innerProc
AS
BEGIN
SELECT 'innerProc 1',@@TRANCOUNT
BEGIN TRAN
SELECT 'innerProc 2',@@TRANCOUNT
ROLLBACK
SELECT 'innerProc 3',@@TRANCOUNT
END
GO -----------------------------------------
CREATE PROC outerProc
AS
BEGIN
SELECT 'outerProc 1',@@TRANCOUNT
BEGIN TRAN
SELECT 'outerProc 2',@@TRANCOUNT
EXEC innerProc
SELECT 'outerProc 3',@@TRANCOUNT
ROLLBACK
SELECT 'outerProc 4',@@TRANCOUNT
END
GO -----------------------------------------
EXEC outerProc
What they do?
outerProc
begins transaction (@@TRANCOUNT = 1)- executes
innerProc
(@@TRANCOUNT at the beginning of the proc = 1) innerProc
begins another transaction (@@TRANCOUNT = 2)innerProc
rollbacks transaction (@@TRANCOUNT = 0)- AND HERE IS THE PROBLEM: @@TRANCOUNT at the beginning of the
innerProc
is not equal to @@TRANCOUNT at the end. What am I doing wrong? Is it correct approach?