Adding a new column sounds simple, but precision matters. In SQL, a new column alters the shape of your data and the contract between your application and the database. Whether you are adjusting PostgreSQL, MySQL, or a distributed system like CockroachDB, the process must be explicit and predictable.
To add a new column, use ALTER TABLE. Define the column name, data type, and constraints in one statement. For example:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This adds last_login with a default value for all future rows. Without a default, existing rows may contain NULL, which can break joins or filters. Decide up front how legacy data should behave.
If the table is large, plan for lock time. Some databases will block writes while adding a column with a default. Others, like PostgreSQL 11+, can add a nullable column instantly, but filling it with default values still needs a second step. Examine the execution plan for production safety.