Adding a new column seems simple, yet it is where databases break, migrations stall, and systems slow. The wrong approach locks tables. The right one ships without downtime.
In SQL, ALTER TABLE is the standard command to add a column. The syntax is direct:
ALTER TABLE table_name
ADD COLUMN column_name data_type;
This works, but on large production datasets it can trigger a full table rewrite. That means blocking writes and reads until the operation finishes. On small tables it’s instant; on huge ones it’s a risk.
Modern strategies use online schema change tools like pt-online-schema-change or native features like MySQL’s ALGORITHM=INPLACE or PostgreSQL’s ADD COLUMN with default NULL. These allow the schema to evolve while the table stays responsive. Avoid setting a non-null default on creation in PostgreSQL; it will rewrite the table. Instead, add the column as nullable, backfill in batches, then enforce constraints.