How do I Change the Data Type for a column in MySQL?

In this tutorial we will learn How to Change the data Type for a column in MySQL As changing the datatype of any column is a making change in the definition of a table and for making changes in the definition of a table we use alter command where Alter command is used for making the changes in the definition os table.

As we know we can change the definition in many ways like changing the name if the column or adding a new column to the table so in each case we can not use the same command so for changing the datatype we use modify command with Alter command to change the data type of the column.

Data Type

Change the data Type Of The Column

As for making any changes in the data of the table, we use the update command but for changing the definition of the table we use the Atlet command and to change the data type of column we use modify clause so let’s take an example to understand it in better ways.

ALTER TABLE your_table_name
MODIFY COLUMN column_name BIGINT;

This is exactly how we can change the data type from any of the given to BIGINT in this example but we can change to any of the MySQL supported data types.

Note

It is said to be a bit risky to change the data type of an existing column as there might be a case where data is lost which was stored earlier as the new data type you entered might not support the old data type in that case the data not supporting to new data type will be lost somewhere which can not retrieve anyhow.

 

To learn more visit Changing tada type of column

And also visit MySQL Problems And Tutorials to learn more about MySQL and for learning different programming languages and solve the problems related to them visit beta python for programing Solutions

Leave a Comment

%d bloggers like this: