Adding a new column sounds simple, but real production work lives in edge cases. Schema changes can lock queries, multiply downtime, and break deployments if done without care. The goal is to add the column fast, keep the system online, and avoid data loss.
First, decide on the column name, type, and default value. In SQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
In most systems, this statement runs instantly for small tables. For large datasets, the execution plan matters. Some databases rewrite the whole table. Others create the column in place. On PostgreSQL, adding a nullable column without a default is fast. Adding a non-null column with a default can lock writes.
Safer workflows use migrations. Tools like Liquibase, Flyway, or native ORM migrations manage version control for schema. Run changes in staging first. Test queries and app functions that depend on the new column before promoting to production.