Common operations under MySQL

Source: Internet
Author: User

This article installs MySQL under Linux, recording the most common MySQL statements in the work

MySQL Add field and delete field

To add a field:

To delete a field:

ALTER TABLE ' user_movement_log ' drop column Gatewayid

To adjust the order of fields:

ALTER TABLE ' User_movement_log ' Gatewayid ' gatewayid ' int not null default 0 after RegionID//PRIMARY key ALTER TABLE Tabelname Add new_field_id Int (5) unsigned default 0 NOT NULL auto_increment, add primary key (NEW_FIELD_ID);//Add a new column Al  ter table T2 add d timestamp; ALTER TABLE infos add ex tinyint NOT null default ' 0 ';//delete columns ALTER TABLE t2 drop column c;//rename column ALTER TABLE T1 change  A b integer;  Alter the type of column ALTER TABLE T1 change b b bigint not null;  ALTER TABLE infos change list list tinyint not null default ' 0 ';  Renaming tables ALTER TABLE t1 rename T2; Gazzo citation mysql> ALTER TABLE tablename change depno depno int (5) is not null;  Mysql> ALTER TABLE tablename ADD index index name (field name 1[, field Name 2 ...]); Mysql> ALTER TABLE tablename Add index Emp_name (name), and the index of the primary keyword mysql> ALTER TABLE tablename ADD PRIMARY key (ID); Index of the unique restriction mysql> ALTER TABLE tablename add unique emp_name2 (cardnumber); Delete an index mysql>alter table tablename Drop  index emp_name; Modify table:

Add Field:

    Mysql> ALTER TABLE table_name ADD field_name Field_type; Modify the original field name and type:           mysql> ALTER TABLE table_name change OLD_FI Eld_name new_field_name field_type; Delete field:           mysql> ALTER TABLE table_name DROP field_name;  

Common operations under MySQL

Related Article

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.