The query was slow. The data model was solid, but the numbers needed space. You needed a new column.
Adding a new column is more than altering a table. It is a live operation, a change to the shape of your application’s truth. In SQL, the syntax is simple:
ALTER TABLE orders ADD COLUMN discount_rate DECIMAL(5,2);
But the impact is not. This change touches queries, indexes, and stored procedures. It can cascade through your ORM, break JSON serializers, and force changes in API contracts. In production systems, adding a column must be precise and safe.
Schema changes in relational databases need planning. Consider defaults. Nullability matters. If the column should never have null values, add it as NOT NULL with a default to avoid rewriting old rows. Without this, queries can fail silently or produce inconsistent results.
If the table is large, the operation can lock it. Plan for downtime or use tools that perform online schema changes. MySQL has pt-online-schema-change. PostgreSQL can add nullable columns fast, but adding columns with defaults before version 11 rewrote all rows. Know your database version.