Adding a new column to a database table is simple in theory but can turn costly in production if done wrong. The operation touches structure, data integrity, and sometimes the uptime of critical systems. Done right, it is safe, fast, and invisible to users. Done wrong, it can lock tables, crash services, or corrupt history.
The first step is to define the purpose of the new column. Name it with precision and ensure the data type matches future use cases. Avoid vague types like TEXT when a constrained type will enforce rules and improve performance.
In SQL, the syntax is direct:
ALTER TABLE orders
ADD COLUMN processed_at TIMESTAMP NULL;
For large datasets, test on a staging copy. Measure the migration time. On some engines, adding a new column with a default value rewrites the whole table. That can take hours on tens of millions of rows. In those cases, add the column as nullable first, then backfill in small batches.