MySQL Modify table structure
The following table names test5 only one field hobby operation
Modify Table Name
ALTER TABLE TEST5 rename Newtest;
Change the name of a field at the same time
Statement structure ALTER TABLE name change field name new field name [First|after field name]
First|after can be written or not, the position of the change field is in the foreground or behind a field.
ALTER TABLE newtest change hobby hob char (20);
Just modify the field
Statement Authority ALTER TABLE name modify field name [First|after field name]
Can still change the position of the modified field
ALTER TABLE newtest Modify HOB char (100);
Append field
Statement structure ALTER TABLE name add field name [First|after field name]
ALTER TABLE newtest add tid tinyint first;
Delete a field
Statement structure ALTER TABLE table name drop field name
ALTER TABLE newtest drop TID;
Add primary Key
Statement structure ALTER TABLE name add primary key (field name);
ALTER TABLE Newtest add primary key (ID);
Note that if you have a primary key in the table, you cannot add a primary key and the field contents of the primary key cannot be duplicated.
Delete primary key
Statement structure ALTER TABLE name drop PRIMARY key;
There's no need to emphasize which field is a primary key because one table
MySQL first Knowledge (iii) modifying table structure