MySQL uses the alter table statement to modify the TABLE structure. The following describes how to modify the TABLE structure Statement of MySQL.
Modify Table
Execute the alter table statement for MySQL to modify the TABLE structure. It mainly performs operations on the TABLE structure, you can add or delete columns in a table, create or cancel indexes, change the type of existing columns, change the column or table name, or modify the table annotations and types. The statement format is as follows:
Alter [ignore] table table_name action_list;
The Alter table statement allows multiple actions to be specified. The actions are separated by commas (,). Each action indicates a modification to the table. It can not only perform multiple modifications at the same time, but also change all VARCHAR columns to CHAR columns at the same time, so as to change the table from a table with variable row length to a table with fixed row length. Table 1 lists some common operation statements.
Common functions of MySQL alter table statements
The table is the basic operation method for modifying tables. Other operations are similar to those of tables. To learn more about the action_list parameter, refer to the description of the create_definition parameter in the creation table.
To modify a table, run the following code:
- mysql> use mysql
- Database changed
- mysql> alter table shili change id x-id int ;
- Query OK, 0 rows affected (0.06 sec)
- Records: 0 Duplicates: 0 Warnings: 0
This code changes the field "id" in the shili table to "x-id ".
10 common MySQL command lines
Add new users through MySQL Command Line
Optimize MySQL statement instances through Indexes
Cancel MySQL user permissions
Instances that grant MySQL user permissions