The query ran fast and then failed.
A missing field. A schema mismatch. A forgotten migration.
You need a new column, and you need it now.
Adding a new column to a database table should be precise and safe. The wrong command can lock tables, stall writes, or break dependencies. The right approach depends on your database engine, your schema design, and the size of your data set.
In SQL, the basic syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But in production, you need more than syntax. For large tables, adding a new column without downtime means using online schema changes or migration tools like pt-online-schema-change for MySQL or native concurrent operations in PostgreSQL. These methods reduce locks and keep traffic flowing.
Choosing defaults matters. Adding a NOT NULL column with a default value can rewrite the entire table and cause long locks. In PostgreSQL, using ADD COLUMN ... DEFAULT ... after version 11 stores the default in metadata, avoiding a full rewrite. In MySQL, use DEFAULT with caution, or consider NULL with an application-level backfill.