Was this helpful?
BEGIN TRANSACTION Statement
The BEGIN TRANSACTION statement declares the beginning of a multi-statement transaction (MST). MSTs contain one or more SQL statements to be processed as a single, indivisible database action. Many SQL statements are allowed within an MST; others, however, are not. The phrase, within an MST, is strictly defined to indicate statements appearing between an initial BEGIN TRANSACTION statement and a final END TRANSACTION statement.
After beginning an MST with begin transaction, the MST can be terminated by either committing or aborting the transaction. Use the END TRANSACTION statement to commit the MST and the abort statement to undo the MST. Ingres automatically aborts the MST in cases of deadlock.
Note:  SET LOCKMODE is not permitted within an MST. BEGIN TRANSACTION and END TRANSACTION cannot be nested within an MST.
This statement has the following format:
BEGIN TRANSACTION
BEGIN TRANSACTION Examples
The following example begins an MST, executes SQL statements, and commits the updates to the database:
BEGIN TRANSACTION;
INSERT INTO emp (name, sal, bdate)
     VALUES ('Jones,Bill', 10000, 1914);
INSERT INTO emp (name, sal, bdate)
     VALUES ('Smith,Stan', 20000, 1948);
END TRANSACTION; \g
/* commits both inserts to table */
The following example begins an MST, executes SQL statement, and aborts the transaction, thus canceling the updates:
BEGIN TRANSACTION;
INSERT INTO emp (name, sal, bdate)
     VALUES ('Jones,Bill', 1000000, 1814);
INSERT INTO emp (name, sal, bdate)
     VALUES ('Wrong,Tony', 150, 2021);
ABORT; \g
/* undoes both inserts; table is unchanged */
Last modified date: 04/03/2024