The ALTER TABLE statement in MySQL can be used to change the data type of a column in an existing table. The following is the fundamental syntax for changing the data type of a column:
Following is the query to alter the data type of an existing column in a table in MySQL
ALTER TABLE `YourTableName` MODIFY `YourColumnName` <YourDataType> NULL;
You would perform the following query, for instance, if you had a table called “User” and wanted to alter the “Weight” column’s data type from INT to DECIMAL(10, 2):
ALTER TABLE User MODIFY COLUMN Weight DECIMAL(10, 2);
When you change the data type of a column, MySQL will attempt to convert the existing data in that column to the new data type. If this is not possible due to data loss or other problems, the ALTER TABLE statement will fail with an error.
By substituting the CHANGE keyword for MODIFY in the ALTER TABLE statement, you can alter both the column name and the data type at once.
ALTER TABLE YourTableName CHANGE COLUMN YourOldColumnName YourNewColumnName YourNewDataType;
Prior to making any changes, please be sure to take a backup of the table and test it in a development environment before implementing it in a production environment.
Further, you can verify the column data type with the help of this blog: