How can I change the position of a certain existing column in MySQL table?
Ex: I want to move the column username from its current position to
ALTER TABLE `Customers` MODIFY `UserName` INT (11) AFTER `Orders`
Done! One line changes position and there's nothing else to do.
I advise against @rahim-asgari recommendation of ALTER TABLE MYTABLE ADD MYFILED INT( 5 ) NOT NULL AFTER POSITION
, since you'll to:
ALTER TABLE `TableName` MODIFY `FieldToBeMoved` [SAME FIELD SETTINGS] [ACTION] `TargetPosition`
[SAME FIELD SETTINGS]
Refers to the configuration of your field. TINYINT, VARCHAR, TEXT, etc. Remember to include the size. Ej. varchar (255)
[ACTION]
You can move a field BEFORE
or AFTER
a specific field.
Replace for BEFORE
or AFTER
accordingly.
If your...
Customers
UserName
UserName
settings: int(11)
Orders