Lesson 25: ALTER TABLE & Schema Migrations
26 Jul 2026 1 min Swarnil Singhai
Schemas evolve as requirements change — ALTER TABLE modifies an existing table's structure without losing existing data.
Real-time example
Adding a loyalty_points column to an existing customers table with a million rows, safely, in production.
ALTER TABLE customers ADD COLUMN loyalty_points INT DEFAULT 0;
ALTER TABLE orders ALTER COLUMN status SET NOT NULL;
ALTER TABLE orders RENAME COLUMN amt TO amount;
What's happening
Adding a column with a DEFAULT backfills existing rows with that value — on huge tables this can lock the table, so real migration tools do it carefully.
In production, schema changes are usually run through a migration tool (Flyway, Liquibase) so every environment applies them identically.
Advertisement