|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 4:26 AM
Points: 60,
Visits: 174
|
|
Hi, we use XACT_ABORT to rolback if statements failed.
I have a scenario where I have a stored proc that call other stored proc inherently.
Store Proc Main hold following
Begin Exec StoredProc1; -- this stored proc perform insert Exec StoredProc2; -- this stored proc perform insert.Update End; Now can I use XACT_ABORT in main stored proc, so if any of sp failed (StoredProc1,StoredProc2....), it may rollback all ?
Begin xact_abort on Exec StoredProc1; -- this stored proc perform insert Exec StoredProc2; -- this stored proc perform insert.Update xact_abort off End;
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 10:05 AM
Points: 6,730,
Visits: 11,779
|
|
XACT_ABORT may work, but I would recommend you use TRY/CATCH instead for managing exceptions and transactions.
BEGIN TRY;
BEGIN TRAN;
Exec StoredProc1; -- this stored proc perform insert Exec StoredProc2; -- this stored proc perform insert.Update
COMMIT;
END TRY BEGIN CATCH IF XACT_STATE() != 0 ROLLBACK TRAN;
DECLARE @err_str VARCHAR(2048), @err_sev INT, @err_state INT; SELECT @err_str = ERROR_MESSAGE(), @err_sev = ERROR_SEVERITY(), @err_state = ERROR_STATE(); RAISERROR(@err_str, @err_sev, @err_state); END CATCH;
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|