Adding a new column to a database table is one of the most common schema changes, yet it’s also one of the most critical. The choice of data type, the handling of defaults, the timing of the migration, and the way your application reads and writes to it all matter. Done right, it’s seamless. Done wrong, it breaks production.
To add a new column in SQL, you use ALTER TABLE. For example:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP NULL;
This command modifies the table in place, adding last_login to store timestamps. But the database engine’s behavior here depends on the system you run. In PostgreSQL, adding a nullable column is fast. Adding a column with a DEFAULT can require a full table rewrite unless managed with DEFAULT + NOT NULL applied in stages. On MySQL, depending on the storage engine, the operation may lock writes.
If your new column must be populated with existing data, consider a zero-downtime migration process: