Adding a new column sounds simple, but in production systems, it is an operation with consequences. You must consider data integrity, schema evolution, and migration impact before touching the database. Whether you use PostgreSQL, MySQL, or a cloud-native data store, the way you introduce a column defines how well your system scales in the future.
Start with the schema definition. In SQL, this is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But raw SQL is only the surface. You must track the change in version control. You must apply it through migrations that can run in CI/CD pipelines. You must ensure backward compatibility so services reading the table do not fail when the column exists but is empty.
When the new column stores critical data, set defaults where possible. Avoid nulls unless your system can handle them gracefully. For large tables, adding a column with a default can lock the table for a long time, so consider adding it without a default first, then backfilling data in controlled batches.