MySQL Modify table Structure command

Source: Internet
Author: User

Modify table name (RENAME)

1. Pass the ALTER keyword

ALTER TABLE tbl_name RENAME [to | As] new_name;

2. By rename keyword

RENAME TABLE tbl_name to New_name; (to not omit)


Adding a field (add)

ALTER TABLE tbl_name ADD field Name field type [integrity constraint] [first | After field name];

[First | After field name]: Specifies the location of the field

Delete field (drop)

ALTER TABLE tbl_name DROP field name


Modify field type, integrity constraint, location (MODIFY)

ALTER TABLE tbl_name MODIFY field Name field type [integrity constraint] [first | After field name];

Modify field name (change)

ALTER TABLE tbl_name change old field name new field Name field type [integrity constraint] [first| After field name];


Add defaults (SET default)

Alter TABLE tbl_name ALTER FIELD name SET default value;

Delete defaults (drop default)

Alter TABLE tbl_name ALTER FIELD name DROP default value;


Add primary Key

ALTER TABLE tbl_name ADD [CONSTRAINT [symbol]] PRIMARY key[index_type] (field name, ...);

Delete primary key

ALTER TABLE tbl_name DROP PRIMARY KEY;


Add unique

ALTER TABLE tbl_name ADD [CONSTANT [symbol]] UNIQUE [INDEX | KEY] [index name] (field name, ...);

Remove unique

ALTER TABLE tbl_name DROP {INDEX | KEY} index_name;


Modify the table's storage engine

ALTER TABLE tbl_name engine= storage engine name;


Set self-growing values

ALTER tbl_name auto_increment= value;


This article is from the "zgw285763054" blog, make sure to keep this source http://zgw285763054.blog.51cto.com/11591804/1879303

MySQL Modify table Structure command

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.