Adding a new column sounds trivial until it meets production reality. Schema changes can break queries, stall deployments, or lock tables under load. The right approach depends on the scale of your system, the database type, and the need for zero downtime.
Start with clarity on column definition. Decide the name, data type, default value, and nullability. In SQL, you can run:
ALTER TABLE orders ADD COLUMN delivery_date TIMESTAMP;
For small tables, this is fast. On large datasets, it can block reads and writes. PostgreSQL can run ALTER TABLE ADD COLUMN instantly if the column is nullable without a default. MySQL, depending on version, may need a table copy.
To add a new column without downtime, use an online schema change tool. Examples include gh-ost and pt-online-schema-change for MySQL, or pg_online_schema_change for PostgreSQL. These migrate data in chunks, reduce lock contention, and allow the column to appear without breaking requests.
Consider data backfill. After adding a nullable column, populate it in batches. Avoid a single massive update. Break it into transactions small enough to commit quickly, reducing impact on indexes and replication lag.