ALTER TABLE … MODIFY/CHANGE lets you safely convert a column to a new data type in MySQL.
Update a column’s type to store larger numbers, switch to an optimized type, or add precision—without creating a new column. Refactoring keeps application code and reports consistent.
Use ALTER TABLE
with either MODIFY COLUMN
(keep the same name) or CHANGE COLUMN
(rename and change type in one step).
Choose MODIFY
when the column name stays the same.It rewrites metadata only, leaving the name untouched.
Pick CHANGE
to rename the column while converting the data type. You supply both old and new names.
Always cast to a compatible type or create a backup. Test with a SELECT CAST()
preview to check for truncation before running the DDL.
Yes. MySQL rebuilds indexes on the altered column.Make sure referenced columns share identical types and lengths to prevent constraint errors.
Add ALGORITHM=INPLACE, LOCK=NONE
to let MySQL apply the change with minimal blocking when possible (InnoDB only).
Run on a replica first, verify metrics, schedule during low-traffic windows, and monitor the slow query log for regressions.
The Orders.total_amount
needs more precision after a currency switch.
ALTER TABLE Orders
MODIFY COLUMN total_amount DECIMAL(12,2) NOT NULL,
ALGORITHM=INPLACE, LOCK=NONE;
Marketing wants Customers.email
renamed to email_address
and lengthened.
ALTER TABLE Customers
.
CHANGE COLUMN email email_address VARCHAR(320) NOT NULL;
No, MySQL converts each value in place; data remains unless the new type can’t accommodate it.
Yes, run another ALTER TABLE to the previous type, but ensure intermediate casts don’t lose precision.
Duration depends on row count, storage engine, and whether MySQL can use an in-place algorithm. Test on staging first.