Adding a new column to a database table is simple to describe but easy to get wrong in production. Schema changes touch live data, impact queries, and can lock tables if executed carelessly. The right approach depends on the database engine, the size of the table, and the tolerances for downtime.
In SQL, the basic syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This command creates the new column instantly on small tables. On large, high-traffic systems, the same action can block writes or cause replication lag. Tools like pt-online-schema-change or gh-ost can perform non-blocking migrations on MySQL. For PostgreSQL, adding a column with a default that is not NULL will rewrite the table, so adding it without a default first and backfilling later is faster.
When introducing a new column to support an application feature, maintain backward compatibility between schema and code. Deploy the schema change first, then update application logic to read from and write to the new column. Only after all instances are writing consistently should you remove any old fields or migrations.