Jump to content

Database transaction

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GregRobson (talk | contribs) at 00:10, 26 May 2003 (Article created). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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.