Adding a new column is one of the most common schema changes, yet it’s also one of the most dangerous if done carelessly. A single ALTER TABLE can block writes, lock rows, and stall production traffic. The key is to approach it with precision and an understanding of how your database engine handles schema changes at scale.
In SQL, you add a new column with a statement like:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works, but under load it can cause downtime. The impact depends on the database:
- PostgreSQL: Adding a column with a default value rewrites the table. Adding a nullable column without default is fast.
- MySQL: Modern versions with
ALGORITHM=INPLACEcan add columns without a table copy, but defaults may still trigger costly updates. - SQLite: Adding a simple column is immediate, but removing or changing it later requires rebuilding the table.
When you plan a new column, decide the type, nullability, default values, and indexing strategy before execution. Avoid premature indexing — create the new column first, then backfill data in small batches. Once the data is stable, add the index in a separate migration to reduce lock contention.