Adding a new column to a database is simple in syntax, but the decision is not always simple in impact. Schema changes affect performance, migrations, and how your application handles data. Treat every new column with the same rigor as a new feature in your codebase.
In SQL, the command is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works in MySQL, PostgreSQL, and many relational databases with minor syntax differences. Use ALTER TABLE ... ADD COLUMN to define the name, type, and constraints. Always check whether the column should allow null values. For high-traffic production systems, adding a large column with a default value can lock the table and block queries. Test it on staging with production-like data before deployment.
If the new column stores data derived from existing fields, you may want to backfill in batches to avoid locking and write amplification. For example:
UPDATE users
SET last_login = NOW()
WHERE last_login IS NULL
LIMIT 1000;
In systems with zero-downtime requirements, use an online schema migration tool such as pg_online_schema_change or gh-ost. These tools let you add a new column with minimal blocking.