Adding a new column is one of the most common and dangerous changes to a live database. It alters the contract between your application and its data. The wrong data type, the wrong constraints, or a poorly planned rollout can cause downtime, corrupt data, or break production code.
Before creating a new column, define its purpose. Decide the data type with precision. Use constraints to enforce integrity. If the column will be frequently queried, consider indexing, but weigh the cost of write performance and storage.
In SQL, the change is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
In PostgreSQL and MySQL, this runs quickly if the column allows null values and has no default. Large tables can lock writes during the change if you add a non-nullable column with a default. To avoid disruption, run the addition in phases. First, add the column as nullable. Then backfill data in small batches. Finally, set constraints when the table is ready.