Knowledgebase

Altering Table Structure Print

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

Adding, changing and removing columns.

WHEN YOU WOULD

Adding a column for custom data Widening a column that is rejecting values Adding an index Correcting a type

For application tables, prefer the application's own mechanism. Changing structure by hand puts you out of step with what the code expects.

IN PHPMYADMIN

The Structure tab lists columns with options to edit, drop and add.

BACK UP FIRST

Structure changes on a large table rewrite it, take time, and lock it while running.

On a busy site, do this at a quiet hour.

WIDENING A COLUMN

Safe. Existing data is preserved.

NARROWING ONE

Dangerous. Values longer than the new limit are truncated or rejected.

CHANGING A TYPE

Converting text to a number, or similar, can lose or mangle data. Test on a copy first.

DROPPING A COLUMN

Permanent. The data is gone.

FOR FRAMEWORK APPLICATIONS

Use migrations. Changing the database by hand means the next deployment disagrees with it.


Was this answer helpful?
Back

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


Trustpilot