Home > Database > Mysql Tutorial > body text

How to modify the data type of mysql column?

青灯夜游
Release: 2020-09-30 17:18:14
Original
19123 people have browsed it

How to modify the data type of mysql column: Modify it through the "ALTER TABLE" statement with the MODIFY keyword, the syntax "ALTER TABLE

MODIFY

How to modify the data type of mysql column?

Modify field (column) data type

Modifying the data type of a field is to convert the data type of the field into another data type. The syntax rules for modifying field data types in MySQL are as follows:

ALTER TABLE <表名> MODIFY <字段名> <数据类型>
Copy after login

Among them:

  • Table name: refers to the name of the table where the field whose data type is to be modified is located;

  • Field name: refers to the field that needs to be modified;

  • Data type: refers to the new data type of the modified field.

Example:

Use ALTER TABLE to modify the structure of table tb_emp1, and change the data type of the name field to VARCHAR(22) into VARCHAR(30), the SQL statement and running results are as follows.

mysql> ALTER TABLE tb_emp1
    -> MODIFY name VARCHAR(30);
Query OK, 0 rows affected (0.15 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> DESC tb_emp1;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| col1   | int(11)     | YES  |     | NULL    |       |
| id     | int(11)     | YES  |     | NULL    |       |
| name   | varchar(30) | YES  |     | NULL    |       |
| col2   | int(11)     | YES  |     | NULL    |       |
| deptId | int(11)     | YES  |     | NULL    |       |
| salary | float        | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
Copy after login

After the statement is executed, it is found that the data type of the name field in table tb_emp1 has been modified to VARCHAR(30), and the modification is successful.

Recommended tutorial: mysql video tutorial

The above is the detailed content of How to modify the data type of mysql column?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!