Adding a new column is one of the most common changes in a database. It sounds simple, but the impact can be large. The design choice affects performance, storage, and future migrations. Whether you work with SQL or NoSQL, adding a new column means making changes to schema, code, and possibly live production data.
In SQL, a new column is defined with ALTER TABLE. The syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This example adds a timestamp column without dropping or recreating the table. However, on large datasets, adding a column with a default value can lock the table for a long time. Plan this work during low-traffic windows or use online schema change tools.
In PostgreSQL, adding a column without a default is instant. Adding it with a default writes new values to every row. MySQL behaves differently by engine type; InnoDB often rewrites the whole table. Knowing these details avoids downtime.