Adding a new column should be fast, predictable, and safe. Done right, it keeps your schema clean and your application logic clear. Done poorly, it can lock tables, slow queries, or break production. This guide walks through how to add a new column in a way that scales with your data and your team.
First, decide if the new column belongs in the same table. If it can be derived or normalized out, skip it. Every column is a contract with the future. Check its data type, size, and nullability. Avoid defaults unless they have a real and tested value.
For relational databases like PostgreSQL and MySQL, use an ALTER TABLE statement to add the column. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITH TIME ZONE;
On large tables, this can be expensive. PostgreSQL will rewrite the table if you add a column with a non-null default. To avoid downtime, add the column as nullable first, backfill in batches, then apply constraints. In MySQL, watch the storage engine; InnoDB handles many operations online, but keep an eye on locking for older versions.