advancedSQL Fundamentals — DDL, DML & Constraints

You need to add a NOT NULL column 'status' to a 500-million-row orders table in production. How do you do this without downtime?

PostgreSQL approach (zero-downtime): 1) ADD COLUMN with DEFAULT: ALTER TABLE orders ADD COLUMN status VARCHAR(20) DEFAULT 'ACTIVE'. PostgreSQL 11+ writes the default to catalog metadata only (no row rewrite) — instant. 2) Backfill if needed: UPDATE orders SET status = 'ACTIVE' WHERE status IS NULL (do in batches). 3) Add NOT NULL: ALTER TABLE orders ALTER COLUMN status SET NOT NULL (fast if no nul

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is the logical execution order of a SELECT statement?← Back to all SQL questions