Adding a new column should be fast, safe, and predictable. In modern databases, the cost of schema changes can cascade, breaking queries, performance assumptions, or pipelines. The right approach keeps data available while evolving structure.
A new column in SQL starts with ALTER TABLE. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This changes the table definition without touching existing data, assigning NULL to rows where the value isn’t set. For large tables, naive execution can lock writes. Production systems must watch lock times, disk I/O, and replication lag.
Databases like PostgreSQL can add a nullable column without a table rewrite, if no default is specified. MySQL and others may behave differently; in older versions, even adding a nullable column can rewrite the table. Use EXPLAIN to verify impact on your environment.
If you must assign a default to the new column, understand whether it is stored on disk or calculated at read time. Persistent defaults write to every row at creation, which can block for minutes or hours on large datasets. Avoid full rewrites by adding the column first, then using batched updates in application-safe increments.