Adding a new column sounds simple, but in production systems, it can break queries, block writes, and stall deploys. The goal is speed without risk. Achieving that requires planning, the right SQL syntax, and a strategy to handle live traffic.
In MySQL, the basic command is:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
Both may lock the table if the dataset is large. For high-traffic systems, use online DDL migrations. In MySQL, ALGORITHM=INPLACE or tools like gh-ost help. PostgreSQL supports adding a column with a default of NULL without locking reads or writes—but setting a non-null default on creation rewrites the table, which is slow. Add the column first, then backfill in small batches.