When you add a new column to a database table, you are altering the schema—the contract between your application and its data. Done right, it extends capabilities. Done wrong, it breaks production.
Start by defining the column precisely. Give it a clear name that matches your domain language. Choose the smallest data type that fits the need. Avoid nullable columns unless there is a strong case for them. Defaults matter. They prevent existing rows from throwing errors and can speed up integration with the application layer.
In SQL, the standard syntax is straightforward:
ALTER TABLE table_name
ADD COLUMN column_name data_type DEFAULT default_value;
For large datasets, think about lock time. Many databases lock the table while adding a column. On PostgreSQL, adding a column with a default can rewrite the table. Minimize downtime by adding the column without a default, then updating values in batches, then setting the default for new rows.