The query runs, returns rows, and you realize you need a new column. Not later. Now.
Adding a new column should be simple, but in production it can be dangerous. Schema changes lock tables, stall writes, and create downtime if handled wrong. To avoid this, many teams use zero-downtime migrations. A new column can be added first, backfilled, then deployed without breaking existing queries.
In SQL, the basic syntax is clear:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But the real work starts after the DDL runs. You must decide on defaults. If a column needs a non-null constraint, populate it before enforcing that rule. For large datasets, batch updates with limits to reduce load:
UPDATE users
SET last_login = NOW()
WHERE last_login IS NULL
LIMIT 1000;
Track progress until all rows have valid data. Then apply constraints and update indexes.