manojadams
manojadams

Reputation: 2430

Change column order in MySQL

Is it possible to change the order of columns in MySQL (using phpMyAdmin XAMPP) by which they appear without dropping the current table?

Upvotes: 5

Views: 6885

Answers (3)

Giorgio Barchiesi
Giorgio Barchiesi

Reputation: 6157

How to do it by using PhpMyAdmin:

  • Show table structure
  • On the relevant row (i.e. database column) click on "Modify"
  • On the extreme right, choose the new position form the "Move field" combo box
  • Optionally, click on "Show preview" to see what SQL query will be run (also useful for automatically repeating the procedure in another instance of the same database)
  • After closing the preview box, click on "Save"

Done!

Upvotes: 2

Vineesh K S
Vineesh K S

Reputation: 1964

Try this

ALTER TABLE `table_name`
    MODIFY COLUMN `column_name1` varchar(100) AFTER `column_name2`;

Upvotes: 11

abresas
abresas

Reputation: 835

I'm not sure about phpMyAdmin, but you can certainly do that with an SQL query:

ALTER TABLE `table`
CHANGE COLUMN `oldname` `newname` *column_definition* [AFTER|BEFORE] `colname`;

Upvotes: 5

Related Questions