How to Change the Order of the Fields on MySQL

In MySQL, having a logical order for the columns, or fields, sometimes makes managing a table easier. If you did not create your tables in this fashion, you may use the "ALTER TABLE" syntax to change the order of the columns. When you make the change, MySQL attempts to save the data contained in your table, but you should still back-up your data before making any changes. If you need to change the order for multiple fields, you have to enter a different query for each change you make.

Instructions

    • 1

      Log in to your MySQL server and open up the query interface.

    • 2

      Type in the following query:

      ALTER TABLE table_name MODIFY COLUMN first_column INT AFTER second_column;

      Substitute the correct "table_name." The "first_column" is the column you want to move so it comes directly after "second_column."

    • 3

      Execute the query. MySQL will rearrange the order of the fields based on your query. Repeat the query if you need to change the order for more than one field.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured