Explanation of the three commonly used relational database transaction II: basic transaction commands

Second, the transaction Basic command

Description: command,

| (Vertical bar) separate brackets or braces syntax items. Use only one of them.
[] (Square brackets) Optional syntax items. Do not type the brackets.
{} (Braces) Required syntax items. Do not type the braces.

 1. SQL SERVER

1) BEGIN { TRAN | TRANSACTION } [ { transaction_name | @tran_name_variable } [ WITH MARK [ 'description' ] ] ] [ ; ]

Represented explicitly open a name or a value transaction_name @tran_name_variable a local transaction.

2)BEGIN DISTRIBUTED { TRAN | TRANSACTION } [ transaction_name | @tran_name_variable ] [ ; ]

Expressed explicitly open a name for the value transaction_name or @tran_name_variable of distributed transactions

3)COMMIT [ { TRAN | TRANSACTION } [ transaction_name | @tran_name_variable ] ] [ WITH ( DELAYED_DURABILITY = { OFF | ON } ) ] [ ; ]

Represents commit the transaction and release the transaction resources, all data changes since the beginning of the transaction will become a permanent part of the database. In brackets content may be omitted, so COMMIT transaction with COMMIT TRANSACTION submit the same function.

4)COMMIT [ WORK ] [ ; ]

Submit and ends the transaction. With the same functionality COMMIT TRANSACTION, COMMIT TRANSACTION but to accept the specified transaction name. This syntax is compatible with SQL-92.

5)ROLLBACK { TRAN | TRANSACTION } [ transaction_name | @tran_name_variable | savepoint_name | @savepoint_variable ] [ ; ]

He said it would roll back the transaction to save the designated starting point or point to remove from the starting point of a transaction to save all of the data points and releases associated resources. Parentheses may be omitted in the content, the same as the rollback transaction ROLLBACK TRANSACTION ROLLBACK function.

6)ROLLBACK [ WORK ] [ ; ]

The transaction is rolled back to the beginning of the transaction. ROLLBACK TRANSACTION with the same function, but ROLLBACK TRANSACTION to specify the transaction name. This ROLLBACK is compatible with ISO standards.

When nesting transactions, ROLLBACK WORK always rolls back to the farthest BEGIN TRANSACTION statement, @@ TRANCOUNT system function and reduced to 0

7)SAVE { TRAN | TRANSACTION } { savepoint_name | @savepoint_variable } [ ; ]

Set transaction savepoint within a transaction. savepoint_name is the name assigned to the save point. @ Savepoint_variable is a valid name to save user-defined variable containing the name of the point.

8)SET TRANSACTION ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SNAPSHOT | SERIALIZABLE }

Set the transaction isolation level.

The BEGIN  TRANSACTION TR_ACCOUNTTRANSFER;
 - A 1000 yuan account subtracting 
the UPDATE  [ the dbo ] . [ ACCOUNT ]  
  the SET AMOUNT = AMOUNT - 1000.00 
the WHERE  [ NAME ]  =  ' A ' ; 

- B account number plus 1000 yuan 
the UPDATE  [ the dbo ] . [ ACCOUNT ] 
  the SET AMOUNT = AMOUNT +  1000.00 
the WHERE  [ NAME ]  =  ' B';
COMMIT TRANSACTION TR_ACCOUNTTRANSFER;

2. MYSQL

  MySQL, the database engine only uses Innodb database or table only support transactions.

1)START TRANSACTION | BEGIN [WORK]

START TRANSACTIOn or BEGIN [WORK] are used to open the transaction.

2)COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]

Commit the current transaction, since the transaction after the change became permanent change.

3)ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]

Roll back the transaction to the starting point of a transaction, cancel all changes during the transaction.

4)SAVEPOINT identifier

Create a save point specified identifier in the transaction .

5)ROLLBACK [WORK] TO SAVEPOINT identifier

The transaction is rolled back to the save point specified in the transaction.

6)RELEASE SAVEPOINT identifier

Delete specified transaction save point.

7)SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL 

{ READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }

Set the transaction isolation level.

The BEGIN 
- A 1000 yuan account subtracting 
the UPDATE ACCOUNT 
  the SET AMOUNT = AMOUNT - 1000.00 
the WHERE NAME =  ' A ' ; 

- B account number plus 1000 yuan 
the UPDATE ACCOUNT
  the SET AMOUNT = AMOUNT +  1000.00 
the WHERE NAME =  ' B ' ;
 a COMMIT ;

3. ORACLE

   Oracle transaction starting to execute the first SQL statement, without specifying the start and end of a transaction, a transaction would mean the end of the next transaction begins. The transaction is terminated in the following four cases:

  • COMMIT or ROLLBACK command without a SAVEPOINT clause.
  • When the user runs the DDL command, an implicit commit. DDL commands such as: CREATE, DROP, RENAME, or ALTER.
  • When the database connection is disconnected.
  • The client process terminates abnormally, resulting in a transaction is implicitly rolled back.

1)COMMIT

Submit all changes in the transaction, the transaction ends.

2)ROLLBACK

Roll back all the changes the transaction, the transaction ends.

3) SAVEPOINT identifier

Create a save point, so that you can change the transaction is rolled back to the save point.

 4)ROLLBACK TO SAVEPOINT identifier

Change to the specified savepoint rollback affairs.

5)RELEASE SAVEPOINT identifier

Delete the specified save point.

6)SET TRANSACTION [ READ ONLY | READ WRITE ]

[ ISOLATION LEVEL [ SERIALIZE | READ COMMITED ]

[ USE ROLLBACK SEGMENT 'segment_name' ]

[ NAME 'transaction_name' ];

Set the transaction attribute.

- A 1000 yuan account subtracting 
the UPDATE ACCOUNT 
  the SET AMOUNT = AMOUNT - 1000.00 
the WHERE NAME =  ' A ' ; 

- B account number plus 1000 yuan 
the UPDATE ACCOUNT
  the SET AMOUNT = AMOUNT +  1000.00 
the WHERE NAME =  ' B ' ;
 a COMMIT ;

Guess you like

Origin www.cnblogs.com/markkang/p/12110071.html