Difference between revisions of "Portable SQL/Statements/Transactions"

From Linuxnetworks
Jump to: navigation, search
(inital)
 
(starting transactions)
Line 1: Line 1:
== Start transactions ==
+
== Starting transactions ==
  
Database vendors use various statements for starting transactions and there is no single string that fits for all.
+
The ANSI SQL standard defines a statement for starting new transactions:
 +
 
 +
START TRANSACTION
 +
 
 +
Unfortunately, database vendors use various different statements for starting transactions and there is no single string that fits for all.
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 10: Line 14:
 
|-
 
|-
 
! MySQL
 
! MySQL
| BEGIN
+
| BEGIN [WORK], START TRANSACTION (4.0.11)
 
|-
 
|-
 
! Oracle
 
! Oracle
Line 16: Line 20:
 
|-
 
|-
 
! PostgreSQL
 
! PostgreSQL
| BEGIN
+
| BEGIN, SET TRANSACTION mode
 
|-
 
|-
 
! SQLite
 
! SQLite
| BEGIN
+
| BEGIN [TRANSACTION]
 
|-
 
|-
 
! SQL Server
 
! SQL Server
Line 27: Line 31:
 
| BEGIN TRANSACTION  
 
| BEGIN TRANSACTION  
 
|}
 
|}
 +
 +
The statement which fits for the most popular Open Source databases is BEGIN because it is understood by MySQL, PostgreSQL and SQLite.
  
 
== Saving changes ==
 
== Saving changes ==

Revision as of 22:37, 6 May 2007

Starting transactions

The ANSI SQL standard defines a statement for starting new transactions:

START TRANSACTION

Unfortunately, database vendors use various different statements for starting transactions and there is no single string that fits for all.

Database Statement
Firebird SET TRANSACTION
MySQL BEGIN [WORK], START TRANSACTION (4.0.11)
Oracle SET TRANSACTION ISOLATION LEVEL READ COMMITTED
PostgreSQL BEGIN, SET TRANSACTION mode
SQLite BEGIN [TRANSACTION]
SQL Server BEGIN TRANSACTION
Sybase ASE BEGIN TRANSACTION

The statement which fits for the most popular Open Source databases is BEGIN because it is understood by MySQL, PostgreSQL and SQLite.

Saving changes

Making the changes done within a transaction permanent is easily done with a single statement for all databases:

COMMIT

Discarding changes

To undo all changes done within a transaction is as easy as committing them. A single statement for all databases exists:

ROLLBACK



Back to Overview