MySQL Add, delete fields, adjust fields

Source: Internet
Author: User

How should MySQL add fields be implemented? This is a lot of new contacts MySQL database has been mentioned, the following is to introduce you to MySQL add fields and delete the field method, I hope you can be enlightened.

MySQL add field:

ALTER TABLE ' User_movement_log ' add column Gatewayid int not null default 0 after ' RegionID ' (which field is added later)

To delete a field:

ALTER TABLE ' user_movement_log ' drop column Gatewayid

To adjust the order of fields:

alter table  ' User_movement_log '  CHANGE  ' 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    alter  table t2 add d timestamp;  alter table infos add ex  tinyint not null default  ' 0 ';//Delete Column    alter table t2 drop  column c;//Renaming Columns    alter table t1 change a b integer;   //changing 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)  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);// Index    mysql> alter table tablename add primary key (ID) of the main keyword;// Index    mysql> alter table tablename add unique emp_name2 with unique restriction conditions (cardnumber);//delete an index    mysql>alter table tablename drop index emp_ Name


Add Field:


MySQL Add, delete fields, adjust fields

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.