Adding a new column to a database table is one of the most common schema changes. It sounds simple, but in large production systems it can break deploys, lock tables, or slow queries if not done with care. The right approach depends on your database engine, the size of your table, and the constraints you set.
In SQL, the basic form is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works instantly on small tables. On large tables with high traffic, it can cause downtime. PostgreSQL will often need to rewrite the whole table when you set a default value on a new column, while MySQL can sometimes add columns faster with instant DDL. Consider adding the column first without a default or a NOT NULL constraint, backfilling in small batches, and then setting constraints after the data is populated.
For production-safe schema migrations, wrap your change in a migration tool. Tools like Flyway, Liquibase, or built-in Rails migrations can help you manage version control and rollbacks. Always test migrations on a staging copy of production data before running them live.