Knowledgebase

Running SQL Queries Safely Print

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

Using the SQL tab without breaking things.

THE DISCIPLINE

Write a SELECT first, with the same WHERE clause you intend to use for the UPDATE or DELETE.

Run it. Look at what comes back. Those are exactly the rows your change will affect.

Only then change SELECT to UPDATE or DELETE.

This single habit prevents nearly every serious accident.

THE CLASSIC DISASTER

UPDATE without a WHERE clause changes every row in the table.

DELETE without a WHERE clause empties it.

There is no undo. Only your backup.

BEFORE ANY WRITE QUERY

Export the table.

CHECK WHAT IS SELECTED

The database name appears at the top. Running against the wrong one is the second most common accident.

READING THE RESULT

phpMyAdmin reports how many rows were affected.

If you expected one and it says four thousand, you have a problem and your backup is now relevant.

USE LIMIT WHILE TESTING

Adding LIMIT 1 to an UPDATE restricts the damage while you confirm the syntax.


Was this answer helpful?
Back

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


Trustpilot