Adding a new column should be simple, but the wrong approach can lock tables, slow queries, or take the application offline. Precision matters.
In SQL, the standard command is clear:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works for MySQL, PostgreSQL, and most other relational databases, with small syntax variations. Always define the column type and decide whether to allow NULL. For production, avoid NOT NULL without a default. That change can rewrite the entire table and cause downtime.
For PostgreSQL, adding a NULL-able column is nearly instant, regardless of table size. Adding a NOT NULL column with a default is optimized in newer versions, but older versions rewrite the table. MySQL behaves differently by storage engine—InnoDB can block writes for schema changes unless you use ALGORITHM=INPLACE or ALGORITHM=INSTANT (v8.0+).