Was this helpful?
Examples: Begin Transaction
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: 01/30/2023