shox
shox

Reputation: 1160

Change mysql column rows

i have a mysql table structure :

emails( id , name , email ) 

how i can change the order of the table to

emails( id , email ,name  ) 

Upvotes: 1

Views: 119

Answers (5)

fvu
fvu

Reputation: 32953

Based on the comment you added, ie you want to copy table data between databases, have a look at SquirrelSQL and its DBCopy plugin, that might provide you with a more universal approach and leaner, faster way to achieve your goal. And it works between databases of different brands as well.

Upvotes: 0

Paul Sonier
Paul Sonier

Reputation: 39480

Try this:

ALTER TABLE emails MODIFY COLUMN name AFTER email 

Upvotes: 1

Oswald
Oswald

Reputation: 31647

  1. Create a new table with a different name
  2. Copy the values of the old table to the new table
  3. Delete the old table
  4. Create a table with the old name
  5. Copy the values again

However, this should not be necessary if you adhere to best practices (like stating the names of the columns that you want to retrieve and the names of the columns that you want to set).

Upvotes: 0

Suroot
Suroot

Reputation: 4423

Looks like this is what you want.

ALTER TABLE emails MODIFY COLUMN name `name_data_type` after email;

Upvotes: 4

André Laszlo
André Laszlo

Reputation: 15537

Try this:

ALTER table `emails`
       MODIFY COLUMN `name` your_data_type
       AFTER `email`

Read more in the MySQL documentation.

Upvotes: 3

Related Questions