The data table is ready, but the schema is missing a piece. You need a new column.
Adding a new column is one of the most common changes in a database. Done right, it’s fast, safe, and reversible. Done wrong, it locks queries, breaks code, and causes downtime. The right approach depends on the database engine, the table size, and whether you require zero-downtime deployment.
Start with the schema definition. In SQL, you use ALTER TABLE to add a new column:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works instantly for small tables. For large datasets, though, adding a new column can trigger a full table rewrite. In production, that can take hours. Use online schema change tools like pt-online-schema-change for MySQL or CONCURRENTLY operations for PostgreSQL where available.
Define nullability and defaults with intention. Adding a column with NOT NULL and no default will fail if existing rows lack a value. If you must enforce constraints, add the column as nullable, backfill data in batches, then apply constraints in a separate migration. This avoids locking and preserves performance.