The query returned fast, but the table was missing something. A new column.
Adding a new column to a database should be deliberate. It changes the schema, affects queries, and can ripple through code and services. Done right, it’s clean and safe. Done wrong, it’s downtime, broken pipelines, and corrupted data.
In SQL, the basic syntax is simple:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP;
In practice, you need more than syntax. For large datasets, adding a column locks the table in many engines. This can block reads and writes for minutes or hours. Plan around traffic patterns. Use rolling deployments. Test migration scripts against production-like data.
When adding a new column with defaults or constraints, avoid making the database backfill every row at once. Add the column as nullable. Deploy. Then backfill in batches. Finally, add constraints or make it non-nullable in a second migration. This keeps the schema in sync without downtime.