[Linux] [MySQL] command change table structure: Add, delete, modify fields, adjust field order

Source: Internet
Author: User
Tags mysql commands

Original source: http://www.phpernote.com/MySQL/1120.html

1 frequently used MySQL commands to change the table structure of some SQL statements, including adding, deleting, modifying fields, adjusting the order of the fields. 2 3 To Add a field:4 5ALTER TABLE ' User_movement_log ' Add column Gatewayid int notNULL default0After ' RegionID '; (which field is added later)6 7 To delete a field:8 9 ALTER TABLE ' user_movement_log ' drop column Gatewayid;Ten  One To adjust the order of fields: A  -ALTER TABLE ' user_movement_log ' Change ' Gatewayid ' "Gatewayid ' int notNULL default0After RegionID; -  the //PRIMARY Key -  -ALTER TABLE tabelname add new_field_id int (5) unsigneddefault0 notNULLAuto_increment, add PrimaryKey(new_field_id); -  + //Add a new column -  + ALTER TABLE T2 add d timestamp; AALTER TABLE infos add ex tinyint notNULL default' 0 '; at  - //Delete Column -  - ALTER TABLE T2 drop column C; -  - //Renaming Columns in  -ALTER TABLE T1 change a Binteger; to  + //changing the type of a column -  theALTER TABLE T1 change b b bigint notNULL; *ALTER TABLE infos changeList Listtinyint notNULL default' 0 '; $ Panax Notoginseng //Renaming a table -  theALTER TABLE T1RenameT2; +  A Gazzo Primer the  + MySQL> ALTER TABLE tablename change depno depno int (5) notNULL; - MySQL>ALTER TABLE tablename ADD index index name (field name 1[, field Name 2 ...]); $ MySQL>ALTER TABLE tablename Add index Emp_name (name); $  - index of the plus primary keyword -  the MySQL> ALTER TABLE tablename Add primaryKey(ID); - Wuyi index with unique restriction criteria the  - MySQL>ALTER TABLE tablename add unique emp_name2 (cardnumber); Wu  - Delete an index About  $ MySQL>ALTER TABLE tablename DROP INDEX emp_name; -  - To Modify a table: -  A Add Field: +  the MySQL>ALTER TABLE table_name ADD field_name field_type; -  $ Modify the original field name and type: the  the MySQL>ALTER TABLE table_name change old_field_name new_field_name field_type; the  the To delete a field: -  in MySQL> ALTER TABLE table_name DROP field_name;

[Linux] [MySQL] command change table structure: Add, delete, modify fields, adjust field order

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.