Adding a new column in your database schema is not just a schema change. It affects queries, indexes, migrations, and application logic. Choosing how to add it depends on your environment, your database engine, and your tolerance for downtime.
In SQL, the simplest way is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works well in development or small datasets. In production, a direct ALTER TABLE can lock the table. For large datasets, use an online migration strategy. Tools like pt-online-schema-change or gh-ost allow adding a new column without blocking writes.
Consider column defaults carefully. Adding a NOT NULL column with a default forces a full table rewrite in many databases. On PostgreSQL, adding a column with no default is fast, but backfilling data later is safer for high-traffic systems. MySQL and MariaDB behaviors differ; test migrations in a staging environment.