Adding a new column sounds simple. In practice, it can break queries, impact performance, and disrupt production if done wrong. The right approach depends on context: schema design, migration strategy, data volume, and uptime requirements.
In SQL databases, creating a new column involves an ALTER TABLE statement. The syntax is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works fine for small datasets. For large tables, the operation can lock writes and cause downtime. The solution is an online schema change tool or a migration system that batches changes safely. Popular options include pt-online-schema-change for MySQL and gh-ost for low-impact migrations.
For NoSQL databases like MongoDB, adding a new field is implicit. Documents can store it when the application starts writing the value. Even here, backfilling or default values can be costly at scale, so streaming updates or lazy migration patterns are standard.