Adding a new column is more than just altering a table. It changes the shape of your data. It changes the contracts between code and storage. If you do it without a plan, you risk downtime, failed migrations, and angry users.
First, define the purpose of the new column. Decide on the data type with care. Text, integer, boolean, timestamp—choose the smallest type that fits the need to save space and speed queries. Avoid nullable columns unless they have a clear reason to exist. Enforce constraints from the start so bad data never enters.
In SQL, the core syntax is simple:
ALTER TABLE users ADD COLUMN last_seen TIMESTAMP NOT NULL DEFAULT NOW();
In production, it gets harder. On large datasets, ALTER TABLE can lock writes. For zero-downtime migrations, add the column as nullable, backfill the values in batches, then apply NOT NULL constraints. Use feature flags in the application layer so code can handle both old and new schemas until the migration is complete.