I am executing a critical stored procedure that will execute UPDATE , DELETE and INSERT , and I want my TRANSACTION be properly formed.
I saw several TRANSACTION statements where there is a check after each step. I also saw this view, where the entire set of steps is simply placed in one TRANSACTION block without any โcontrol pointsโ along the way.
Is it a well-formed TRANSACTION that rolls back everything, i.e. UPDATE , DELETE and INSERT if there is any error at any point.
Here's the TRANSACTION :
BEGIN TRANSACTION BEGIN TRY UPDATE SomeTable SET SomeColumnValue = 123 WHERE Id = 123456 DELETE FROM SomeOtherTable WHERE Id = 789 INSERT INTO ThirdTable (Column1, Column2) VALUE ('Hello World', 1234567) END TRY BEGIN CATCH ROLLBACK TRANSACTION END CATCH
source share