MySQL alter add uses record

Source: Internet
Author: User

The alter ADD command is used to increase the table's fields.

Alter ADD command format: ALTER TABLE name add field type other;

For example, a field passtest is added to table MyClass, the type is int (4), and the default value is 0:
Mysql> ALTER TABLE MyClass add passtest int (4) default ' 0 ';

1) Gazzo Primer
Mysql> ALTER TABLE name add index index name (field name 1[, field Name 2 ...]);

Example: mysql> ALTER TABLE employee ADD index emp_name (name);

2) Index of the plus primary keyword
Mysql> ALTER TABLE name add primary key (field name);

Example: mysql> ALTER TABLE employee ADD primary key (ID);

3) Index with unique restriction conditions
Mysql> ALTER TABLE name add unique index name (field name);

Example: mysql> ALTER TABLE employee add unique emp_name2 (cardnumber);

4) Delete an index
mysql> ALTER TABLE name DROP INDEX name;

Example: Mysql>alter table employee DROP index emp_name;

5) Add Field
mysql> ALTER TABLE table_name ADD field_name Field_type;

6) Modify the original field name and type
mysql> ALTER TABLE table_name change old_field_name new_field_name field_type;

7) Delete field
mysql> ALTER TABLE table_name DROP field_name;

MySQL alter add usage record

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.