Adding a new column is one of the most common schema changes in database work. It sounds simple, but in production it can break application logic, stall deployments, or lock writes. The right approach depends on your database engine, migration strategy, and uptime requirements.
In SQL, the standard syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works for PostgreSQL, MySQL, and most other relational databases. But the cost of adding a new column varies. On small tables it’s instant. On large ones it can be a blocking operation that stops queries until it completes. Some databases rewrite the entire table to store the new column. Others, like PostgreSQL for nullable columns with a default of NULL, optimize the change with metadata-only operations.
When adding a new column with a default value, pay attention. For example:
ALTER TABLE users ADD COLUMN status TEXT DEFAULT 'active';
In older versions of MySQL, this will trigger a full table copy. In PostgreSQL 11+, it can be instant if you use a constant default. Understanding your database version and how it handles DDL changes is key.