B. SQL Statements from Earlier Releases : Begin Transaction Statement : Examples: Begin Transaction
 
Share this page                  
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 */