BEGIN
Description
Start a transaction using BEGIN. If the isolation level or read/write mode is specified, a new transaction will have those characteristics. You can also specify them by referring to SET TRANSACTION.
Precautions
None
Syntax
BEGIN [ WORK | TRANSACTION ]
[
{
ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ }
| { READ WRITE | READ ONLY }
} [, ...]
];
Parameters
- WORK | TRANSACTION
Specifies an optional keyword in the BEGIN format and does not have any actual effect.
- ISOLATION LEVEL
Specifies the transaction isolation level that determines the data that a transaction can view if other concurrent transactions exist.
The isolation level cannot be changed after data is modified using SELECT, INSERT, DELETE, UPDATE, or COPY in the transaction.
Value range:
- READ COMMITTED: Only committed data can be read. This is the default value.
- READ UNCOMMITTED: After this isolation level is set, its behavior is the same as that of READ COMMITTED.
- REPEATABLE READ: Only the data committed before the transaction starts can be read. Uncommitted data or data committed in other concurrent transactions cannot be read.
- SERIALIZABLE: Currently, the M-compatible database does not support this isolation level. Setting this isolation level is equivalent to REPEATABLE READ.
- READ WRITE | READ ONLY
Specifies the transaction access mode (read/write or read only).
Examples
-- Create a schema. m_db=# CREATE SCHEMA tpcds; -- Create the tpcds.reason table. m_db=# CREATE TABLE tpcds.reason (c1 int, c2 int); -- Start a transaction in default mode. m_db=# START TRANSACTION; m_db=# SELECT * FROM tpcds.reason; m_db=# COMMIT; -- Start a transaction in default mode. m_db=# BEGIN; m_db=# SELECT * FROM tpcds.reason; m_db=# COMMIT; -- Start a transaction with the isolation level being READ COMMITTED and the access mode being READ WRITE: m_db=# BEGIN ISOLATION LEVEL READ COMMITTED READ WRITE; m_db=# SELECT * FROM tpcds.reason; m_db=# COMMIT; -- Drop the tpcds.reason table. m_db=# DROP TABLE tpcds.reason; -- Delete a schema. m_db=# DROP SCHEMA tpcds;
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot