Using Transactions

* A transaction is a batch of statements that is executed at once or can be cancelled altogether.

* Use "BEGIN" to start a transaction. After the transaction is done use "COMMIT" to execute it, or "ROLLBACK" to cancel it.

* Example:

test=> BEGIN \g
BEGIN
test=> UPDATE employees SET first_name = 'Nahum' WHERE employee_id = 3 \g
UPDATE 1
test=> INSERT INTO employees (employee_id, first_name, last_name)
test=> VALUES (500, 'Linus', 'Torvalds' ) \g
INSERT 18680 1
test=> DELETE FROM employees WHERE employee_id = 54 \g
DELETE 1
test=> COMMIT \g
END


* Changes that are made during the transaction are visible to queries within the transaction. Yet, they only become visible to the outside world, after the transaction was commited.