ALTER TABLE users MODIFY COLUMN username varchar(255);
The ALTER TABLE query above is used to modify the column username in the users' table to have a data type of varchar(255).
The basic syntax to change the column type in MySQL will be as below.
ALTER TABLE table_name MODIFY COLUMN column_name TYPE
To change a column to TEXT data type we can use the below MySQL query.
ALTER TABLE employees MODIFY COLUMN about_employee TEXT;
This query is used to change the data type for multiple columns in a MySQL database.
ALTER TABLE table_name MODIFY COLUMN column_name_1 TYPE, MODIFY COLUMN column_name_2 TYPE;
In the above MySQL query:
1. The ALTER TABLE keyword is used to change the structure of an existing table.
2. The MODIFY COLUMN keyword is used to change the data type of an existing column.
3. In this query, the data type of column_name_1 and column_name_2 is being changed.
MySQL query example
ALTER TABLE users MODIFY COLUMN user_id INT(10), MODIFY COLUMN user_email VARCHAR(50);