The query came in at 3:04 a.m. The schema had changed. The table needed a new column, and there was no margin for error.
Adding a new column in a live database is routine work until it isn’t. Schema changes in production touch every query, index, and service that depends on them. Without a plan, a single ALTER TABLE can lock writes, slow reads, or crash workloads.
The right approach starts with understanding column types, defaults, and constraints. Use the smallest type that fits the data. Decide if NULL values are allowed. If the new column requires a default, set it explicitly to avoid inconsistent states.
On large datasets, a direct ALTER TABLE can be expensive. Many SQL engines rewrite the entire table when a structural change occurs. For small or medium tables, run the migration in place during low-traffic hours. For very large tables, use an online schema change tool like pt-online-schema-change or gh-ost. These utilities create a shadow copy of the table, add the new column there, and swap it in with minimal blocking.