The table is ready. The query runs fast. But it needs a new column.
Adding a new column is one of the most common schema changes in modern databases. It sounds simple, but every system has trade‑offs. Done wrong, it stalls deployments, locks tables, or causes downtime. Done right, it lands in production without a ripple.
To add a new column, start with the database’s native ALTER TABLE syntax. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
In MySQL, the syntax is similar, but engine and version matter. Older versions of MySQL will lock the entire table for the duration of the change. Newer versions with instant DDL can apply the change without heavy locks.
Plan for data type decisions early. A new column that holds text may need a VARCHAR with a defined length for indexing performance. A numeric column should match precision requirements to avoid overflow or rounding errors. Always consider NULL vs. NOT NULL — enforcing NOT NULL without defaults can block inserts until you backfill existing rows.