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!