The query returns. A table fills the screen. But something is missing: the new column you need.
Adding a new column should be fast, predictable, and safe. Whether you are evolving a schema in PostgreSQL, MySQL, or any other relational database, the method matters. The right approach avoids downtime, reduces migration risks, and preserves data integrity.
To add a new column in SQL, you use ALTER TABLE. The simplest form:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works, but production databases rarely stay simple. Adding a new column with a default value can lock a table for longer than your SLA allows. On large datasets, this blocks reads and writes. Modern migrations mitigate this by adding the column without the default, then backfilling data in small batches before applying constraints.
Consider indexing. If the new column will be used in queries, plan for the index after the column exists and is populated. In PostgreSQL: