MySQL Add field and delete field

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:

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

To delete a field:

    1. ALTER TABLE ' user_movement_log ' drop column Gatewayid

To adjust the order of fields:

  1. ALTER TABLE ' user_movement_log ' Gatewayid ' gatewayid ' int not null default 0 after RegionID
  2. Primary key
  3. 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
  4. ALTER TABLE T2 add d timestamp;
  5. ALTER TABLE infos add ex tinyint NOT null default ' 0 ';//Delete Column
  6. ALTER TABLE T2 drop column c;//rename columns
  7. ALTER TABLE T1 change a b integer;
  8. Changing the type of a column
  9. ALTER TABLE T1 change b b bigint not null;
  10. ALTER TABLE infos change list list tinyint not null default ' 0 ';
  11. Renaming a table
  12. ALTER TABLE T1 rename T2; add index
  13. MySQL> ALTER TABLE tablename change depno depno int (5) is not null;
  14. MySQL> ALTER TABLE tablename ADD index index name (field name 1[, field Name 2 ...]);
  15. MySQL> ALTER TABLE tablename add index Emp_name (name);
  16. MySQL> ALTER TABLE tablename add PRIMARY key (ID); add unique constraint index
  17. MySQL> ALTER TABLE tablename add unique emp_name2 (cardnumber); Delete an index
  18. MySQL>alter table tablename DROP index emp_name; Modify table:

Add Field:

    1. mysql> alter table table_name add  field_name field_type; Modify the original field name and type:  
    2.  
    3. mysql > alter table table_name change old_field_name new_field_ name field_type; Delete field:  
    4.  
    5. mysql>  alter table table_name drop field_name;  
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.