开始交易

开始交易 •启动事务并允许您指定事务隔离级别。

句法

开始交易
   [   transaction_qualifier
     | transaction_isolation_level
     | transaction_qualifier, transaction_isolation_level
     | transaction_isolation_level, transaction_qualifier
   ]

where transaction_qualifier is:

READ { ONLY | WRITE }

where transaction_isolation_level is:

ISOLATION LEVEL
          {   CONSISTENT READ
            | READ COMMITTED
            | REPEATABLE READ
            | SERIALIZABLE
          }

描述

The 开始交易 statement explicitly starts a transaction. The benefit of the 开始交易 statement is that you can override 关于默认事务行为.
默认情况下,Nuodb启用AutoCommit行为。这意味着nuodb启动事务来执行每个语句。运行声明后,Nuodb提交事务。
Transactions can contain one or more statements, including those defined in functions, triggers and stored procedures. During a transaction opened by 开始交易, autocommit behavior is suspended for statements.
When there is no 开始交易 statement then execution of a statement implicitly starts a transaction. Such a transaction is always a read-write transaction that uses the default transaction isolation level and the default autocommit setting.
To end a transaction, specify either a 犯罪 or 回滚 statement (See 犯罪, 回滚)。
In a transaction started with 开始交易, NuoDB executes any 放 AUTOCOMMIT statement (See ) and suspends the specified autocommit behavior until after the transaction ends. For example, specification of 放 AUTOCOMMIT ON inside an explicitly started transaction does not affect that transaction.

参数

READ ONLY | READ WRITE

Defines whether the transaction can only read the data, or can also update the data. READ WRITE is the default.

ISOLATION LEVEL

If you specify an ISOLATION LEVEL then it defines how this transaction can view DML and DDL updates performed by itself and other, concurrent transactions. The ISOLATION LEVEL for a transaction remains in effect until either a 犯罪 or a 回滚 is issued. See Transactions and Isolation Levels for a detailed description of each transaction isolation level that NuoDB supports.

例子

以下是Nuodb支持的交易限定符的示例。有关Nuodb支持的隔离级别的示例,请参阅事务和隔离级别。

START TRANSACTION READ ONLY;
CREATE TABLE t1 (n1 integer);
   /* ERROR: Read only transactions cannot create tables. */
回滚;

START TRANSACTION READ WRITE;
CREATE TABLE t1 (n1 integer);
 INTO  t1 (n1) VALUES (1), (2), (3);
选择 * FROM t1;
 N1
 ---
  1
  2
  3
犯罪;
START TRANSACTION READ ONLY;
UPDATE t1  n1=n1+10;
     /* ERROR: Read only transactions cannot change data. */
回滚;
START TRANSACTION READ WRITE;
UPDATE t1  n1=n1+10;
选择 * FROM t1;
 N1
 ---
 11
 12
 13
犯罪;