MySQL: ALTER COLUMN vs CHANGE vs MODIFY COLUMN

ALTER COLUMN
Used to set or remove the default value for a column. Example:-

ALTER TABLE MyTable ALTER COLUMN foo SET DEFAULT ‘bar’;
ALTER TABLE MyTable ALTER COLUMN foo DROP DEFAULT;

CHANGE COLUMN
Used to rename a column, change its datatype, or move it within the schema. Example:-

ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL FIRST;
ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL AFTER baz;

MODIFY COLUMN
Used to do everything CHANGE COLUMN can, but without renaming the column. Example:-

ALTER TABLE MyTable MODIFY COLUMN foo VARCHAR(32) NOT NULL AFTER baz;
The official documentation for ALTER TABLE (for MySQL 5.1) is here.

Unknown's avatar

Author: Makarand Thengdi

Director of Engineering, DevOps, and Releases at LeadSquared, with over a decade of experience in leading engineering and DevOps transformations for high-growth companies. Passionate about optimizing software delivery pipelines, cloud infrastructure, and security compliance. In this blog, I share my learnings and insights on DevOps, cloud technologies, and modern software engineering, reflecting my journey from code to cloud.

Have something to say ?

This site uses Akismet to reduce spam. Learn how your comment data is processed.