Adding a new column seems simple, but in production systems it can be a high‑risk change. Schema migrations touch live data. The wrong command can lock tables, blow up queries, or destroy performance. Precision matters.
First, decide the exact definition: name, data type, nullability, default value. In PostgreSQL, the basic syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But this is not enough for large datasets. On massive tables, even a small schema change can block traffic. Use ADD COLUMN with a default value carefully—Postgres will rewrite the table, which can take hours. Instead, add the column as nullable with no default, backfill in batches, then set the default and constraints.
In MySQL, ALTER TABLE is also the standard path:
ALTER TABLE orders ADD COLUMN status VARCHAR(20);
Be aware that older MySQL versions may lock the table for the duration. Always know which version and storage engine you are using.