Adding a column seems simple. But the wrong approach can lock tables, block queries, trigger downtime, or corrupt data. The right approach depends on database size, workload, and migration tooling.
In SQL, a new column can be added with an ALTER TABLE statement:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
For small tables, this is fast. For large datasets, it can be dangerous. Some databases rewrite the entire table on ALTER TABLE, causing hours of blocking. Others support instant or metadata-only operations. MySQL’s INSTANT algorithm and PostgreSQL’s ALTER TABLE ... ADD COLUMN ... DEFAULT with a NULL default improve speed.
Schema migration tools like Liquibase, Flyway, or Atlas can version and deploy ADD COLUMN changes safely. Feature flags can help by deploying the empty column first, deploying code that writes to it, and only later making it NOT NULL if needed.