Adding a new column is one of the most common database changes, but also one of the most dangerous if done without care. It can break queries, trigger costly table rewrites, or cause downtime under load. The right approach is fast, safe, and repeatable.
First, define the schema change in explicit terms. Name the column, choose the correct data type, and decide on nullability. Avoid default values for large tables unless they are essential—because they will force the database to rewrite every row.
Use migrations over ad hoc queries. In SQL, the standard form is:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
For large production systems, consider online schema change tools. PostgreSQL can add nullable columns without locking writes, but adding a NOT NULL column with a default will lock and rewrite. MySQL’s behavior depends on the storage engine and version—InnoDB offers instant adds for some column types, but not all. Always test in staging with production-like data volume.