Adding a new column in a database is one of the most common schema changes. It affects performance, storage, and code that reads or writes to that table. The operation can be simple in development and dangerous in production. Large datasets, high traffic, and strict uptime requirements turn a single schema change into a deployment risk.
Before adding a new column, define its data type and constraints with care. Mismatched types cause errors. Nullability impacts indexing and query plans. Defaults can save you from unexpected null values but at the cost of extra storage writes. Choose names that match your existing naming conventions and make sense years later.
In SQL databases, syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
This command works, but execution time depends on the database engine and current load. In PostgreSQL, adding certain types of columns with a default can rewrite the entire table. This can lock writes for minutes or hours. MySQL may block during metadata changes if not configured for online DDL.