Adding a new column should be simple. Too often, it isn’t. Schema migrations run in production can block writes, lock tables, or cause downtime. The larger the table, the higher the stakes. The wrong approach can slow queries for hours. The right approach keeps your application online while your schema evolves.
A new column in SQL alters the structure of your table. In PostgreSQL, MySQL, and most relational databases, the ALTER TABLE command is the starting point:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
On small tables, this runs in milliseconds. On large ones, consider online migrations. PostgreSQL handles ADD COLUMN with a default NULL efficiently, avoiding a full table rewrite. But adding a column with a non-null default can still lock the table.
For application-facing services, new columns often need backfill. This requires updating millions of rows without killing performance. Break the job into batches. Use short transactions. Monitor replication lag. Always test on staging with realistic data sizes.