Database transaction

In database products the ability to handle transactions allows the user to ensure that integrity of a database is maintained.

Programs often carry out several SQL queries to perform different functions. When this happens it is important to be sure that the database is not left with only some of the queries carried out. This could lead to problems with other queries that are reliant on the database being consistent.

To ensure the integrity of the data a transaction is used, this consists of multiple queries. When programming with transactions the following method is used.


 * 1) Start a transaction
 * 2) Execute several SQL queries (although these aren't actually executed yet)
 * 3) Finish the transaction

When the transaction is finished (using the COMMIT statement normally) each query is carried out in turn. Should any query fail then the effects of that query and the ones before it are undone. There are only two options with transactions all or none of the queries are carried out.

Transactions are supported in some form or other in databases like PostgreSQL, MySQL and Oracle.