Adding a new column to a database table should be fast, safe, and predictable. It is a common change, but one with sharp edges if handled incorrectly. A bad migration can lock tables, break queries, or cause downtime. Choosing the right method to add a column depends on your database engine, the size of your data, and your deployment strategy.
In SQL, the command is simple:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But simplicity in syntax hides complexity in execution. For small tables, this is near-instant. For large production datasets, it can trigger a full table rewrite. On PostgreSQL, adding a column with no default is cheap. Adding one with a default can be costly unless you use DEFAULT NULL first and then update in batches.
In MySQL, online DDL can reduce downtime, but not every engine or storage format supports it. In SQLite, every ALTER TABLE has limitations that may require creating a new table and copying data.