MySQL ALTER COLUMN Keyword
The MySQL ALTER COLUMN keyword is used to change the data type of a column in an existing table.
Syntax
The syntax for using ALTER COLUMN statement to modify datatype of a column in MySQL is given below:
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
Example:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age |
---|---|---|---|
1 | John | London | 25 |
2 | Marry | New York | 24 |
3 | Jo | Paris | 27 |
4 | Kim | Amsterdam | 30 |
In this table, the datatype of City column is VARCHAR(100). To change the datatype of the column to VARCHAR(255), the statement is given below:
ALTER TABLE Employee MODIFY COLUMN City VARCHAR(255);
This will change the datatype of City column from VARCHAR(100) to VARCHAR(255). For a complete reference of all the data types available in MySQL, see Data Types reference.
❮ MySQL Keywords