Adding a new column sounds simple, but in production systems, it can turn into a knife fight with downtime, performance hits, and data integrity risks. The right approach depends on table size, database type, and uptime requirements.
First, define the new column with the correct data type and constraints. Use ALTER TABLE … ADD COLUMN for most relational databases, but beware — in some systems, this locks the table. On large datasets, consider adding the column without a default value, then backfilling in controlled batches to avoid locking or replication lag.
For PostgreSQL, adding a nullable column is instant. Adding a column with a default in older versions rewrites the entire table, so split the default assignment into a separate UPDATE step. MySQL can add a column quickly, but some storage engines require a table copy. Check your version, engine, and configuration flags before touching production.