BEGIN
BEGIN — Start a Transaction Block
Synopsis
BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
where transaction_mode is one of:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
READ WRITE | READ ONLY
[ NOT ] DEFERRABLE
Description
BEGIN initiates a transaction block, that is, all statements after the BEGIN command will be executed in a single transaction until an explicit COMMIT or ROLLBACK is given. By default (without BEGIN), transactions execute in "autocommit" mode, meaning each statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if it succeeds, otherwise a rollback is done).
Statements within a transaction block execute faster because transaction start/commit requires significant CPU and disk activity. Executing multiple statements within a transaction when making related changes also helps ensure consistency: other sessions will not be able to see the intermediate state until all related updates are complete.
If the isolation level, read/write mode, or deferrable mode is specified, the new transaction will have those characteristics, just as if SET TRANSACTION had been executed.
Parameters
WORK
TRANSACTION
Optional keywords. They have no effect.
For the meaning of the other parameters of this statement, see SET TRANSACTION.
Notes
START TRANSACTION has the same functionality as BEGIN.
Use COMMIT or ROLLBACK to terminate a transaction block.
Issuing BEGIN while already inside a transaction block will provoke a warning message. The transaction state is not affected. To nest transactions within a transaction block, use savepoints (see SAVEPOINT).
For backward compatibility reasons, commas between consecutive transaction_modes can be omitted.
Examples
Start a transaction block: BEGIN;