ALTER TABLE tb_article MODIFY COLUMN NAME VARCHAR(50);
Here tb_article is the table name, NAME is the field name, and 50 is the modified length
ALTER TABLE tb_article MODIFY COLUMN NAME CHAR(50);
After modification, the name field type changes from varchar to char
##3. Add columns in mysql:ALTER TABLE tb_article ADD COLUMN name1 VARCHAR(30);
ALTER TABLE tb_article CHANGE name1 name2 VARCHAR(30);
ALTER TABLE tb_article DROP COLUMN name2;
1. Modify one Field length
alter table table name modify column field name type;For example: the test field in the demo table, the original length is 10 characters, the current length needs to be changed to 100 charactersalter table demo modify column test varchar(100);
2. Modify the length of multiple fields
alter table table name modify column field name 1 type 1,modify column field Name 2 Type 2,modify column field name 3 Type 3;For example: the test1, test2, and test3 fields in the demo table originally had a length of 10 characters, but the current length needs to be changed. into 100, 200, 300 charactersalter table demo modify column test1 varchar(100), modify column test2 varchar(200), modifycolumn test3 varchar(300);
The above is the detailed content of How to modify field type, length and add or delete columns in Mysql. For more information, please follow other related articles on the PHP Chinese website!