Method: 1. Use the "alter table table name modify column column name dateType" statement to modify the data type; 2. Use the "alter table table name change old column name new column name type (length)" statement to modify the name. .
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
1. Modify the data type of the field
alter table table_name modify column column_name dateType
The example is as follows:
2. Modify the field name
alter table table_name change old_column_name new_column_name int(11);
Expand knowledge:
1. Add a unique key
alter table table_name add unique key `uniq_column` (`column`);
2. Add a field
alter table table_name add column column_name datatype
3. Delete a field
ALTER TABLE table_name DROP COLUMN column_name
4. Add a column
----alter table students add column 列名 列属性 alter table students add column 语文 varchar(4) NOT NULL ;
----Add to the end of the column by default
after the name of the specified column name
First Add to the first column
Note: MySQL5.7.16 version does not seem to support Second, Third ...
# #alter table students add column 数学 varchar(4) NOT NULL after 出生日期 ;
5. Delete columns
----alter table 表名 drop column 列名 alter table students drop column 成绩;
Recommended learning: mysql video tutorial
The above is the detailed content of How to modify column in mysql. For more information, please follow other related articles on the PHP Chinese website!