Adding a new column in a production database is not just DDL syntax. It’s a change to structure, performance, and future code. The wrong type or default can slow queries, block writes, or bloat storage. The right approach keeps the migration safe and downtime near zero.
First, define the exact column name and data type. Match the type to the data you will store now and later. Avoid premature optimization, but think about index needs. Adding an index with the column during creation can prevent a second pass over the table. If you must backfill data, batch the updates to avoid long locks.
In SQL, the syntax is straightforward:
ALTER TABLE orders ADD COLUMN discount_percent DECIMAL(5,2) DEFAULT 0;
But straightforward does not mean without risk. On large tables, this can lock writes. Some databases support non-blocking schema changes. Check your engine’s documentation and version.