wrap last price rebuild in transaction
This commit is contained in:
parent
31172e7e35
commit
34c811123a
@ -2,6 +2,10 @@ CREATE OR ALTER PROCEDURE pricing.rebuild_lastprice
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON; -- auto-rollback on most errors
|
||||
|
||||
BEGIN TRY
|
||||
BEGIN TRAN; -- start transaction
|
||||
--------------------------------------------------------------------------------
|
||||
-- Reset target tables
|
||||
--------------------------------------------------------------------------------
|
||||
@ -247,4 +251,25 @@ SELECT
|
||||
FROM flag_json f
|
||||
FULL OUTER JOIN seg_json s
|
||||
ON f.customer = s.customer AND f.partgroup = s.partgroup;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Commit if everything succeeded
|
||||
--------------------------------------------------------------------------------
|
||||
COMMIT TRAN;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
-- Ensure transaction is rolled back
|
||||
IF XACT_STATE() <> 0
|
||||
BEGIN
|
||||
ROLLBACK TRAN;
|
||||
END
|
||||
|
||||
-- Optional: cleanup temp table (temp table persists for session until proc end,
|
||||
-- but explicit drop is helpful if you reuse names or want to free resources)
|
||||
IF OBJECT_ID('tempdb..#flagged') IS NOT NULL
|
||||
DROP TABLE #flagged;
|
||||
|
||||
-- Rethrow the original error to the caller
|
||||
THROW;
|
||||
END CATCH;
|
||||
END;
|
||||
|
Loading…
Reference in New Issue
Block a user