Actually, I got a little confused about using nested transaction in stored procedures. I need to call the two/three procedures with in one main procedure.
Eg:
Begin try
Begin Tran -- 1st level transcation
Procedure 1 --will be executed
Procedure 2 --will be executed
End tran -- 1st level transcation
End try
Begin Catch
Rollback tran
End Catch
PROCEDURE 1:
BEGIN TRAN TRAN1
///scripts
COMMIT TRAN TRAN1
PROCEDURE 2:
BEGIN TRAN TRAN2
///scripts
COMMIT TRAN TRAN2
Am I doing it in a right way?
Committing inner transactions is ignored by the SQL Server Database Engine. The transaction is either committed or rolled back based on the action taken at the end of the outermost transaction. If the outer transaction is committed, the inner nested transactions are also committed. If the outer transaction is rolled back, then all inner transactions are also rolled back, regardless of whether or not the inner transactions were individually committed.
Please refer the link https://technet.microsoft.com/en-us/library/ms189336%28v=sql.105%29.aspx