Adding a new column is one of the most common changes in a database. Done right, it’s fast, safe, and future-proof. Done wrong, it locks tables, slows queries, and blocks deploys.
First, define why the new column exists. Is it storing derived data, user input, or a system flag? Keep types tight. Use proper constraints. Avoid nulls unless they are part of the logic. Name it so another engineer understands it without reading the code.
In SQL, the basics are direct:
ALTER TABLE orders ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT 'pending';
But production systems are rarely that simple. On large datasets, ALTER TABLE can cause downtime. Solve this by using database-native online DDL tools or rolling migrations. In PostgreSQL, adding a column with a default can rewrite the table—unless you set the default in a later step. MySQL can block writes unless you use ALGORITHM=INPLACE where supported.
Index only if queries demand it. A misplaced index costs more than it saves. For boolean or low-cardinality columns, skip indexing until profiling confirms need. Use partial or filtered indexes for selective values.