runtime
86 / 88

lesson 86 Warehouse & reporting projects · advanced

Stage, validate & atomically promote a refresh

Validate staged data before replacing a published result.

the idea

Build and validate the candidate before replacing published data. A transaction makes related writes commit together; rollback retains the old snapshot. In this controlled lab the candidate is known to pass. Production needs explicit blocking gates, failure handling, and workload-specific isolation. SQL Server TRUNCATE syntax is not executed here.

tables in this lesson

The challenges use this data. Each column shows its type underneath; → marks a link to another table.

published_totals2 columns · 2 rows
customer_idtext · keytotal_salesreal
C001289
C002116

all 2 rows

refresh_stage2 columns · 2 rows
customer_idtexttotal_salesreal
C001300
C002120

all 2 rows

example

The idea in one query. Press Run to see what it returns; running examples never affects your progress.

example.sql
BEGIN;
DELETE FROM published_totals;
INSERT INTO published_totals
SELECT *
FROM refresh_stage;
ROLLBACK;
SELECT customer_id,total_sales
FROM published_totals;

Watch for: A TRY/CATCH that logs an error is not automatically atomic. This lab models recovery with an explicit rollback, not an actual crashing process.

build it step by step

Each step changes one thing. Run them in order and watch the result change.

  1. Understand the source contract. Fictional extracts, load counts, invalid dates, versioned dimensions, refresh staging and a data catalog. The foundation project is latest-state; separate history and incremental labs demonstrate extensions.

    step-1.sql
    SELECT *
    FROM published_totals;
  2. Execute the transformation. Build and validate the candidate before replacing published data. A transaction makes related writes commit together; rollback retains the old snapshot. In this controlled lab the candidate is known to pass. Production needs explicit blocking gates, failure handling, and workload-specific isolation. SQL Server TRUNCATE syntax is not executed here.

    step-2.sql
    BEGIN;
    DELETE FROM published_totals;
    INSERT INTO published_totals
    SELECT *
    FROM refresh_stage;
    ROLLBACK;
    SELECT customer_id,total_sales
    FROM published_totals;
  3. Test another question. A TRY/CATCH that logs an error is not automatically atomic. This lab models recovery with an explicit rollback, not an actual crashing process.

    step-3.sql
    BEGIN;
    DELETE FROM published_totals;
    INSERT INTO published_totals
    SELECT *
    FROM refresh_stage;
    COMMIT;
    SELECT customer_id,total_sales
    FROM published_totals

challenge 1

Simulate an interrupted promotion: BEGIN, DELETE published_totals, INSERT from refresh_stage, ROLLBACK. Return customer_id,total_sales; the old snapshot must remain.

Return customer_idtotal_salesany row ordertable changes are checked too

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.