Adding a new column sounds simple, but in production systems, every detail matters. You need the right type, constraints, default values, and zero downtime. If the data model is large or actively queried, a careless migration can lock tables, block writes, or fail under load.
The first step: define the purpose of the new column. Decide if it will be nullable, require an index, or hold computed data. Ensure the type matches expected queries. Avoid premature indexing; large indexes on unused columns will waste storage and slow writes.
In SQL, the basic syntax is straightforward:
ALTER TABLE orders ADD COLUMN shipped_at TIMESTAMP;
But in critical environments, apply online schema changes. Use tools like pt-online-schema-change for MySQL or ALTER TABLE ... ADD COLUMN with ONLINE options in PostgreSQL 12+. For massive tables, consider adding the column without defaults first, then backfilling data in batches to avoid locking.