The schema was broken. A single missing field sent queries into chaos. The fix was simple: add a new column.
A new column changes the shape of a database table. In SQL, this means extending a table definition with an ALTER TABLE statement. The syntax depends on the database engine, but most provide a direct way to define the column name, data type, default value, and constraints. Adding a column is not just a structural change. It can impact query performance, indexing strategies, and application code that interacts with the table.
In PostgreSQL:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP WITH TIME ZONE DEFAULT NOW();
In MySQL:
ALTER TABLE users
ADD COLUMN last_login DATETIME DEFAULT CURRENT_TIMESTAMP;
Before creating a new column in a production environment, consider storage cost, replication lag, and locking behavior. Some engines rewrite entire tables during the operation. For large datasets, this can cause service degradation. Modern systems like PostgreSQL support ADD COLUMN without backfilling data when a DEFAULT is not set, reducing migration time.