In MySQL, you can modify the data type of a field in the table through the alter table
statement. The following article will take you through the alter table statement and introduce how to modify the field type. I hope it will be helpful to you.
In MySQL, the alter table statement is used to add, modify, or delete columns (fields) in an existing table.
1. Add a field (column)
alter table 表名 add 字段名 数据类型
Example: Add a field named The new column of "Birthday", the data type is "date"
alter table Persons add Birthday date
Description: The type of the new column "Birthday" is date, which can store dates
2. Modification Field name
alter table 表名 rename column A to B
3. Modify field type
alter table 表名 alter column 字段名 数据类型
Example: Change the table" The data type of the "Birthday" column in Persons" is changed to "year"
alter table Persons alter column Birthday year
Explanation: The data type of the "Birthday" column is year, which can store the year in 2-digit or 4-digit format.
4. Delete fields
alter table 表名 drop column 字段名
Example:Delete the "Birthday" column in the "Person" table
alter table Persons drop column Birthday
Related video tutorial recommendations: "MySQL Tutorial"
The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of How to modify field type in MySQL?. For more information, please follow other related articles on the PHP Chinese website!