Optimizing transactions in Synapse SQL
In simple words, a group of data modification operations is called a transaction. If all operations are successful, we can call it a successful transaction. In a successful transaction, all the modifications are committed and become a permanent part of the database; otherwise, all the data modifications will be erased.
In this section, we are going to learn how to manage transactions in Synapse SQL pools. In the case of any failure, you will need to roll back all the changes made during the execution of stored procedures in order to maintain consistency in your data. You can handle any sort of exceptions in stored procedures using a TRY-CATCH
block, as illustrated in the following code snippet:
SET NOCOUNT ON; DECLARE @xact_state smallint = 0; BEGIN TRAN Â Â Â Â BEGIN TRY Â Â Â Â Â Â Â Â DECLARE @i INT;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ...