A transaction is a set of operations that might include updating, deleting, inserting, and retrieving data. These operations are often embedded in a higher-level language, or can be explicitly wrapped in a transaction block using BEGIN and END statements. A transaction is successfully executed if all the operations with in the transaction are executed successfully. If an operation in a transaction fails, the effect of the partially executed operation on the transaction can be undone.
To control the beginning and end of a transaction explicitly, the BEGIN statement can be used to denote the start of the transaction, and the statements END or COMMIT to denote the end of the transaction. The following example shows how to explicitly execute an SQL statement in a transaction:
BEGIN;
CREATE TABLE employee (id serial primary key, name text, salary numeric);
COMMIT;
One use...