Adding a new column to a database table is simple in theory. In production, it can be dangerous. Schema changes shift data models, break queries, and ripple through codebases. A missing migration step can halt deployments or corrupt data. That is why disciplined handling of the ALTER TABLE operation matters.
Before you add the new column, define its purpose and constraints. Decide on type, nullability, and default values. Avoid nullable columns unless they make sense, because they complicate queries and indexing. If the column stores relational data, enforce it with foreign keys immediately.
In SQL, the common approach is:
ALTER TABLE users
ADD COLUMN last_login_at TIMESTAMP NOT NULL DEFAULT NOW();
This works, but large tables need more care. Locking during schema updates can cause downtime. For zero-downtime migrations, add the column as nullable, backfill data in batches, then apply constraints. Combine this with feature flags to control rollout.