ABORT
Function
ABORT rolls back the current transaction and cancels the changes in the transaction.
This command is equivalent to ROLLBACK, and is present only for historical reasons. Now ROLLBACK is recommended.
For more information about transaction management, see Transaction Management.
Precautions
ABORT has no impact outside a transaction, but will provoke a warning.
Syntax
1 | ABORT [ WORK | TRANSACTION ] ; |
Parameter Description
WORK | TRANSACTION
This keyword is optional and does not affect the ABORT operation.
Examples
The following demonstrates using the ABORT statement to roll back and undo the process of modifying an account balance.
- Create a test table and import data.
1 2 3 4 5 6 7 8 9 10 11 12
-- Create a test table. DROP TABLE IF EXISTS user_account; CREATE TABLE user_account ( id INT PRIMARY KEY, username VARCHAR(20), balance DECIMAL(10,2) ); -- Insert initial data. INSERT INTO user_account VALUES (1, 'lily', 100.00); INSERT INTO user_account VALUES (2, 'lilei', 200.00); -- View initial data. SELECT * FROM user_account;

- Use ABORT to roll back within a transaction.
- Start a transaction.
1BEGIN TRANSACTION;
- Execute a modification operation (deduct Lily's balance).
1UPDATE user_account SET balance = balance - 50 WHERE id = 1;
- View the modified data (temporarily effective within the transaction).
1SELECT * FROM user_account;

- Execute ABORT to roll back (undo all modifications).
1ABORT;
There are also equivalent syntax forms, such as ABORT WORK or ABORT TRANSACTION. The modern syntax uses ROLLBACK.
- Verify the rollback result: The data is restored to its initial values.
1SELECT * FROM user_account;

- Start a transaction.
Helpful Links
Transaction Management, SET TRANSACTION, COMMIT | END, ROLLBACK
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