BEGIN
Description
Starts a transaction using BEGIN. If an isolation level and a read/write mode are specified, a new transaction will have those characteristics. You can also specify them using 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 a transaction isolation level, which determines what data is visible to a transaction if there are other concurrent transactions.
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, this isolation level is not supported in an M-compatible database. It 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