Adding a new column is one of the most frequent schema changes in modern applications. In relational databases like PostgreSQL, MySQL, and SQL Server, the ALTER TABLE command defines the process. The goal is to make the change without breaking queries, slowing deployments, or locking reads and writes.
The basic syntax is direct:
ALTER TABLE table_name
ADD COLUMN column_name data_type;
For production databases, the real work starts before you run the statement. You have to plan. Choose the right data type. Decide on NULL or NOT NULL. Determine if a default value is needed. Defaults on large tables can cause lock times if not handled carefully.
On PostgreSQL, adding a nullable column without a default is instant. Adding a default with ALTER TABLE on a massive table can rewrite the whole thing. To avoid downtime, add the column first as nullable, then backfill data in batches, then enforce NOT NULL.
On MySQL with InnoDB, adding a column may require a table rebuild unless ALGORITHM=INPLACE is supported for your change type. Review your engine's online DDL capabilities to reduce disruption.