The SQL statement collection for the ALTER TABLE of the MYSQL database _mysql

Source: Internet
Author: User

A collection of SQL statements for the ALTER TABLE of MySQL, including adding, modifying, deleting fields, renaming tables, adding, deleting primary keys, and so on.

1: Delete Column

ALTER table "table name" DROP "column name"

2: Adding columns

ALTER table "table name" ADD "column name" INT not NULL COMMENT ' annotation description '

3: Modify the column's type information

ALTER table "table name" Change "column name" new column name (this can be used with the same name as the original column) "BIGINT not NULL COMMENT ' comment description '

4: Renaming a column

ALTER table "table name" Change "column Name" "New column name" BIGINT not NULL COMMENT ' comment description '

5: Renaming tables

ALTER table "table name" RENAME "Table new name"

6: Delete the primary key in the table

Alter table "table name" Drop PRIMARY key

7: Add primary key

ALTER TABLE sj_resource_charges ADD CONSTRAINT pk_sj_resource_charges PRIMARY KEY (resid,resfromid)

8: Add index

ALTER TABLE sj_resource_charges Add index index_name (NAME);

9: Add a unique restricted condition index

ALTER TABLE sj_resource_charges Add unique emp_name2 (cardnumber);

10: Delete Index

ALTER TABLE tablename DROP INDEX emp_name;

The above content is small to introduce to you the MySQL database ALTER TABLE SQL statement set, hope to help everyone!

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.