SQL statement set of alter TABLE in MySql database _ MySQL

Source: Internet
Author: User
SQL statement set of The alter TABLE in mysql, including adding, modifying, and deleting fields, renaming tables, and adding and deleting primary keys. This article introduces the SQL statement set of the alter table of the MySql database. if you are interested, learn about the SQL statement set of The alter TABLE of mysql, including adding, modifying, and deleting fields, rename a table, add or delete a primary key.

1: delete columns

Alter table [TABLE name] DROP [column name]

2: Add columns

Alter table [TABLE name] ADD [column name] int not null comment 'Comment description'

3. modify the column type information.

Alter table [TABLE name] CHANGE [column name] [New column name (here you can use the same name as the original column)] bigint not null comment 'annotation description'

4: rename a column

Alter table [TABLE name] CHANGE [column name] [New column name] bigint not null comment 'annotation description'

5. rename a table

Alter table [TABLE name] RENAME [new TABLE name]

6. delete the primary key in the table.

Alter TABLE [TABLE name] drop primary key

7. add a primary key

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

8: add an index

ALTER TABLE sj_resource_charges add index INDEX_NAME (name);

9: add an index with unique restrictions

ALTER TABLE sj_resource_charges add unique emp_name2(cardnumber);

10: delete an index

alter table tablename drop index emp_name;

The above content is a collection of SQL statements for the alter TABLE of MySql database introduced by Xiaobian. I hope to help you!

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.