Translation reference to convert SQL Server BEGIN and COMMIT transaction to Snowflake SQL
Description
Snowflake SQL, a transaction can be started explicitly by executing a BEGIN statement. Snowflake supports the synonyms BEGIN WORK and BEGIN TRANSACTION. Snowflake recommends using BEGIN TRANSACTION.
A transaction can be ended explicitly by executing COMMIT. Read more about Snowflake Transactions here.
Sample Source Patterns
The following examples detail the BEGIN and COMMIT transaction statements.
SQL Server
IN -> SqlServer_01.sql
CREATEPROCEDURE TestTransactionASBEGINDROPTABLEIFEXISTS NEWTABLE;CREATETABLENEWTABLE(COL1 INT, COL2 VARCHAR);BEGINTRANSACTION;INSERT INTO NEWTABLE VALUES (1, 'MICHAEL');INSERT INTO NEWTABLE VALUES(2, 'JACKSON');COMMITTRANSACTION;END
IN -> SqlServer_02.sql
CREATEPROCEDURE TestTransactionASBEGINDROPTABLEIFEXISTS NEWTABLE;CREATETABLENEWTABLE(COL1 INT, COL2 VARCHAR);BEGINTRANSACTION LabelA;INSERT INTO NEWTABLE VALUES (1, 'MICHAEL');INSERT INTO NEWTABLE VALUES(2, 'JACKSON');COMMITTRANSACTION LabelA;END
Snowflake SQL
OUT -> SqlServer_01.sql
CREATEORREPLACEPROCEDURE TestTransaction ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"transact"}}'
EXECUTEASCALLERAS$$BEGINDROPTABLEIFEXISTS NEWTABLE;CREATE OR REPLACETABLENEWTABLE ( COL1 INT, COL2 VARCHAR );BEGINTRANSACTION;INSERT INTO NEWTABLE VALUES (1, 'MICHAEL');INSERT INTO NEWTABLE VALUES(2, 'JACKSON');COMMIT;END;$$;
OUT -> SqlServer_02.sql
CREATEORREPLACEPROCEDURE TestTransaction ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"transact"}}'
EXECUTEASCALLERAS$$BEGINDROPTABLEIFEXISTS NEWTABLE;CREATE OR REPLACETABLENEWTABLE ( COL1 INT, COL2 VARCHAR );BEGINTRANSACTION !!!RESOLVE EWI!!! /*** SSC-EWI-0101 - COMMENTED OUT TRANSACTION LABEL NAME BECAUSE IS NOT APPLICABLE IN SNOWFLAKE ***/!!!
LabelA;INSERT INTO NEWTABLE VALUES (1, 'MICHAEL');INSERT INTO NEWTABLE VALUES(2, 'JACKSON');COMMIT;END;$$;