Adding a new column is simple in concept and critical in execution. In SQL, ALTER TABLE is the command. The syntax is direct:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP;
This updates the schema without dropping data. Use precise data types to avoid storage waste and future migrations. Define defaults when needed. Be explicit about NULL or NOT NULL. A careless NULL can break downstream queries.
In production, adding a new column can lock tables or block writes. Test schema changes on a staging environment. Measure the impact on query plans. For large tables, consider online schema change tools like pt-online-schema-change or native database features that reduce downtime.
When altering columns, track changes with version control for migrations. In frameworks like Rails or Django, generate migrations and review them carefully. Do not rely solely on automation — inspect the generated SQL.