Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use alter statement in MySQL

Shulou Source: shulou.com Published: 2022-05-31 19:25:17 10月13日 Update

I believe many inexperienced people don't know what to do about how to use the alter sentence in MySQL. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Summary of the usage of alter sentence in MySQL

1: delete column

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 type information of the column

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 'comment description'

4: rename the column

ALTER TABLE [table name] CHANGE [column name] [new column name] BIGINT NOT NULL COMMENT 'comment description' www.2cto.com

5: rename the table

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 constraint index

ALTER TABLE sj_resource_charges add unique emp_name2 (cardnumber)

10: delete the index

Alter table tablename drop index emp_name

After reading the above, have you mastered how to use the alter statement in MySQL? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Name name statement comment index content method more problem helpless for this reason information reason skill condition article type experience industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Shulou Technology Huawei Redmi