Resolution: teach you to master how to change the table column order
First, consider whether it really need to change the table column order. The core elements of SQL from the data storage format for applications. General shall designate the order to retrieve data. In the following section a statement to col_name1, col_name2, col_name3 order to return out; in section 2 statement to col_name1, col_name3, col_name2 order to return the column:
mysql> SELECT col_name1, col_name2, col_name3 FROM tbl_name;
mysql> SELECT col_name1, col_name3, col_name2 FROM tbl_name;
If you decide to change the order listed, perform the following steps:
Column with a new order to create a new table.
Implementation of the statement:
mysql> INSERT INTO new_table
-> SELECT columns-in-new-order FROM old_table;
Remove or rename old_table.
Rename the new table to the original name:
mysql> ALTER TABLE new_table RENAME old_table;
SELECT * is very suitable for testing queries. However, in the application, never rely on the use of SELECT * Do not rely on search out according to their location. If you add, move or delete a column, the column returned by the order and location will remain the same. A simple change on the table structure will cause the application to fail.
Recommended links:
CATIC Shenzhen: HR reform activity trip
Visuanl C # 2005 Quick Start of the while statement (1)
