Adding a new column to an existing table is simple in theory but dangerous in production. Done wrong, it locks tables, stalls queries, or corrupts data. Done right, it ships instantly with zero downtime.
Start by defining exactly what the new column will store. Decide on the data type, nullability, default values, and constraints before writing a single line of SQL. Changing these later is harder, especially if the table stores millions of rows.
For most relational databases, the syntax is clear:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
But the surface is deceptive. An ALTER TABLE can trigger a full table rewrite, blocking reads and writes. On PostgreSQL, adding a column with a constant default prior to version 11 rewrites the table. On MySQL, storage engines behave differently; InnoDB may lock the table during the operation depending on the column definition.