Adding a new column is one of the most common operations in database evolution. It changes the schema, the queries, and sometimes the system’s performance profile. Whether you run PostgreSQL, MySQL, SQLite, or a cloud-native datastore, the principles are the same: define the column, set its type, decide on defaults, and understand the migration’s impact.
In SQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This statement updates the schema without touching existing rows. But the details matter. Adding a NOT NULL constraint with no default will block if data exists. Large tables can lock writes during the operation, depending on the engine. Plan around downtime, or use phased migrations.
For critical systems, adding a new column often happens in two steps. First, create the column nullable with no constraints. Then backfill values in batches to avoid long locks or replication lag. After data is in place, alter the column to enforce NOT NULL or unique constraints.