Adding a new column sounds simple. It rarely is. In production, one wrong move locks tables, drops performance, or corrupts data. The right approach depends on your database, data size, and uptime requirements.
Start with the schema definition. In SQL, ALTER TABLE is the standard for adding a new column. For example:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP;
On small tables, this runs instantly. On large ones, the command can lock writes until finished. For high-traffic systems, that means downtime or degraded performance.
PostgreSQL supports adding new nullable columns without much cost. But adding with a NOT NULL constraint and default value rewrites the whole table, so avoid it in hot paths. Instead, add the column as nullable, backfill data in batches, then apply constraints.
MySQL’s behavior varies by version and storage engine. With InnoDB, online DDL can help, but it is not truly zero-impact. Test in staging with production-like data before touching live systems.