How to modify mysql column data types
This article mainly introduces how to modify the mysql column data type, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
How to modify the mysql column data type: through the "ALTER TABLE" statement with the MODIFY keyword to modify, the syntax "ALTER TABLE MODIFY".
Modify field (column) data type
To change the data type of a field is to convert the data type of the field to another data type. The syntax rules for modifying field data types in MySQL are as follows:
ALTER TABLE MODIFY
Where:
Table name: refers to the name of the table where the field of the data type is to be modified
Field name: refers to the field to be modified
Data type: refers to the new data type of the modified field.
Example:
Use ALTER TABLE to modify the structure of the table tb_emp1, changing the data type of the name field from VARCHAR (22) to VARCHAR (30). The SQL statement and run results are shown below.
Mysql > ALTER TABLE tb_emp1-> MODIFY name VARCHAR (30); Query OK, 0 rows affected (0.15 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > 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) |
After the statement is executed, it is found that the data type of the name field in the table tb_emp1 has been changed to VARCHAR (30), and the modification is successful.
Thank you for reading this article carefully. I hope it is helpful for everyone to share how to modify the data type of mysql column. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you have any problems. Detailed solutions are waiting for you to learn!