Note
Ang pag-access sa pahinang ito ay nangangailangan ng pahintulot. Maaari mong subukang mag-sign in o magpalit ng mga direktoryo.
Ang pag-access sa pahinang ito ay nangangailangan ng pahintulot. Maaari mong subukang baguhin ang mga direktoryo.
Applies to:
Databricks SQL
Commits the current interactive transaction, making all changes across all modified tables permanent. For requirements and usage patterns for interactive transactions, see Interactive transactions.
Syntax
COMMIT [ TRANSACTION | WORK ]
Parameters
This statement has no parameters.
Notes
- If there is no active transaction, executing
COMMITresults in a NO_ACTIVE_TRANSACTION error. - If
COMMITfails, the transaction is aborted and you must explicitly runROLLBACKto reset the transaction state before beginning a new transaction. Common reasons forCOMMITfailures include write conflicts with other concurrent transactions. - To execute this statement, you must have an active transaction and appropriate permissions on all the objects read or modified within the transaction.
Examples
The following examples demonstrate how to commit interactive transactions.
Basic transaction
Run each statement separately.
BEGIN TRANSACTION;
-- Insert a new record
INSERT INTO my_table VALUES (1, 'test');
-- Update records in another table
UPDATE another_table
SET value = 'updated'
WHERE id = 5;
-- Commit all changes in both tables atomically
COMMIT TRANSACTION;
Read-your-own-writes
Run each statement separately.
BEGIN TRANSACTION;
-- Insert new data
INSERT INTO customers VALUES (101, 'New Customer');
-- Update the newly inserted data
UPDATE customers SET name = 'Updated Customer Name' WHERE id = 101;
-- Query sees the updated value within the transaction
SELECT name FROM customers WHERE id = 101;
-- Returns 'Updated Customer Name'
-- Commit makes changes visible to other transactions
COMMIT;
Handle commit failure
If COMMIT fails due to conflicts or other errors, you must explicitly roll back. Run each statement separately.
BEGIN TRANSACTION;
-- Make changes
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
-- Attempt to commit
COMMIT;
-- If COMMIT fails (e.g., due to write conflict),
-- the transaction is aborted
-- You must explicitly roll back before starting a new transaction
ROLLBACK;
Related articles
- BEGIN TRANSACTION (interactive transactions): Begin an interactive transaction
- ROLLBACK: Roll back an interactive transaction and discard all changes
- ATOMIC compound statement (non-interactive transactions): Run multiple SQL statements as a single atomic transaction with automatic commit and rollback
- Transactions: Overview of transaction support, requirements, and limitations
- Transaction modes: Detailed patterns and examples for non-interactive and interactive transactions