Adding a new column is one of the most common schema changes, yet it can bring code, queries, and deployments to a halt if handled poorly. A careless ALTER TABLE can lock rows, stall writes, and block reads. In high-traffic production systems, that’s enough to cause downtime and customer pain. The solution is to approach schema evolution with precision.
To add a new column safely, start by defining the exact data type and constraints. Avoid adding NOT NULL with a default if you expect millions of rows — it can trigger a full table rewrite. Instead, add the column as NULLable, backfill in batches, then tighten constraints in a later migration. Keep each step small and reversible.
In SQL, the basic command is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But in real systems, you must consider indexing, query plans, and application code dependencies. Deploy the schema change first. Deploy application updates that use the new column later. Avoid deploying both in a single release — it’s harder to roll back in an emergency.