Adding a new column is one of the most common schema changes in modern software, but it’s also one of the easiest to get wrong. The wrong approach locks tables, blocks queries, or forces downtime. The right approach keeps systems online, migrates data safely, and preserves performance.
A new column in SQL starts with a simple command. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login timestamptz;
This works on small tables. On large datasets, that same command can block reads and writes. For live systems, best practice is to add the new column as NULL and backfill in batches. Avoid default values that require a full table rewrite.
In MySQL, the process is similar:
ALTER TABLE users ADD COLUMN last_login DATETIME NULL;
But MySQL versions differ in how they handle online changes. Newer releases with ALGORITHM=INPLACE or ALGORITHM=INSTANT can add a column with minimal locking. Older ones can’t. Always check the docs for your engine and version before running any schema change in production.