Using Transactions Print

  • databasesphpmyadmin, databases, database, phpmyadmin, backup, guide, howto, solution
  • 0

Grouping changes so they apply together.

WHAT IT IS

A set of changes treated as one unit. Either all apply, or none do.

Available on InnoDB tables, not MyISAM.

WHY IT HELPS

If you are running several related changes and one fails, a transaction leaves the database as it was rather than half-changed.

THE FORM

START TRANSACTION; your queries here COMMIT;

Or ROLLBACK instead of COMMIT to discard everything.

USING IT AS A SAFETY NET

Start a transaction, run your UPDATE, check the result with a SELECT, then COMMIT if correct or ROLLBACK if not.

That gives you the undo that SQL otherwise lacks.

THE CAVEAT IN PHPMYADMIN

Each submission may run in its own connection, which ends the transaction. Run the whole set in one SQL box submission.

WHEN IT MATTERS MOST

Bulk changes to live data, where a partial application would leave inconsistency.

WHAT IT DOES NOT REPLACE

A backup. A transaction protects against a failure mid-operation, not against a correctly executed mistake you committed.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot