Adding a new column to a database seems simple. It is not. In production, the wrong approach can lock tables, stall queries, or break downstream systems. Speed matters. Precision matters more.
A new column changes the schema. In SQL, the basic statement is:
ALTER TABLE users ADD COLUMN status VARCHAR(50);
But the details depend on the database engine. In PostgreSQL, adding a nullable column is fast, but adding a column with a default value can rewrite the table. In MySQL, the “instant” add is available only on certain storage engines and versions. Always check whether the operation is online or blocking.
If the new column needs default data on billions of rows, do not fill it in a single transaction. Use batch updates. Shift read logic to handle nulls until the population is complete. Migrations should be planned so that schema changes deploy first, followed by backfill jobs, and finally code that depends on the column.