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!