Collection of SQL statements from alter table in MySql database
- 2021-01-03 21:06:39
- OfStack
mysql alter table collection of SQL statements, including add, modify, delete fields, rename tables, add, delete primary keys, etc.
1: Delete columns
ALTER TABLE [Table name] DROP [column name]
2: Add columns
ALTER TABLE [table name] ADD [column name] INT NOT NULL COMMENT 'Notes'
3: Modify the type information for the column
ALTER TABLE [Table name] CHANGE [Column name] BIGINT NOT NULL COMMENT [New column name] BIGINT NOT NULL COMMENT
4: Rename columns
ALTER TABLE [Table name] CHANGE [column name] [New column name] BIGINT NOT NULL COMMENT
5: Rename the table
ALTER TABLE [Table name]
6: Delete the primary key in the table
Alter TABLE [table name] drop primary key
7: Add the primary key
ALTER TABLE sj_resource_charges ADD CONSTRAINT PK_SJ_RESOURCE_CHARGES PRIMARY KEY (resid,resfromid)
8: Add indexes
ALTER TABLE sj_resource_charges add index INDEX_NAME (name);
9: Add index with only 1 constraint
ALTER TABLE sj_resource_charges add unique emp_name2(cardnumber);
10: Drop the index
alter table tablename drop index emp_name;
The above content is this site to you to introduce the MySql database alter table SQL statement collection, I hope to help you!