MySQL alter command, mysqlalter

Source: Internet
Author: User

MySQL alter command, mysqlalter

Use the alter command in mysql to edit the table structure. The details are as follows:

Modify Field Type

mysql> alter table employee change depno depno int(5) not null;

Add Index

Mysql> alter table name add index name (field name 1 [, field name 2…]);

Example:

mysql> alter table employee add index emp_name (name);

Index with primary keywords

Mysql> alter table name add primary key (field name );

Example:

mysql> alter table employee add primary key(id);

Add an index with unique conditions

Mysql> alter table name add unique index name (field name );

Example:

mysql> alter table employee add unique emp_name2(cardnumber);

View the index of a table

Mysql> show index from table name;

Example:

mysql> show index from employee;

Delete An index

Mysql> alter table Name drop index name;

Example:

mysql>alter table employee drop index emp_name;

Modify Table: add field:

mysql> ALTER TABLE table_name ADD field_name field_type;

View table:

mysql> SELECT * FROM table_name;

Modify the original field name and type:

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

Delete field:

ALTER TABLE table_name DROP field_name

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Finally, I wish you a successful pass of the Computer Grade examination.

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.