SQLPathLab
Transactions · Intermediate

ROLLBACK

rolling back a transaction.

Overview

ROLLBACK discards changes in the current uncommitted transaction and releases related resources. It applies only to work that has not been committed, cannot undo an earlier committed transaction, and does not replace backups. Applications should roll back consistently after validation failures or exceptions to avoid partially completed business state.

Basic syntax

ROLLBACK;

Examples

ROLLBACK example

Roll back the tutorial transaction and show its reverted state, illustrating how uncommitted work is abandoned after an error.

Run result

transaction_effect
statementeffectnote
ROLLBACK Undo uncommitted transaction changes; when a savepoint is named, roll back only to it. Actual behavior also depends on the storage engine, isolation level, and session state. Test lock waits, concurrency, and failure recovery in the target MySQL environment.

Common issues

What must happen after BEGIN?

Finish with COMMIT to persist changes or ROLLBACK to undo them; do not leave transactions open.

Can transactions replace backups?

No. Transactions protect operation consistency, while backups support disaster recovery.

Why can a transaction block other requests?

Uncommitted work may retain locks, so keep transactions short and access resources in a consistent order.

Tags

Transactions

Was this explanation clear?