Introduction to modifying table structure statements in MySQL

Source: Internet
Author: User

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:

 
 
  1. mysql> use mysql  
  2. Database changed  
  3. mysql> alter table shili change id x-id int ;  
  4. Query OK, 0 rows affected (0.06 sec)  
  5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.