Adding a new column is one of the most common database changes, yet it often breaks production if done carelessly. Whether working in PostgreSQL, MySQL, or SQLite, the steps must be clean, deliberate, and reversible.
First, choose a clear column name. Avoid ambiguous labels. Make the type explicit: VARCHAR(255) for text, INTEGER for counts, BOOLEAN for flags. Decide on nullability—forcing NOT NULL with no default can lock writes until every row is updated.
Second, update the schema with ALTER TABLE. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
In MySQL:
ALTER TABLE users ADD COLUMN last_login DATETIME;
Each engine has quirks. PostgreSQL handles column additions without rewriting the table if no default is declared. MySQL may lock the table for large datasets unless using online DDL.