|
| 1 | +# Marty — History & Learnings |
| 2 | + |
| 3 | +## Project Context |
| 4 | +**Project:** Time Travelling Data — 20-minute conference presentation on SQL Server temporal tables |
| 5 | +**Tech Stack:** SQL Server / Azure SQL, SSMS, T-SQL |
| 6 | +**User:** Chad Green |
| 7 | + |
| 8 | +## Demo 1 Scope |
| 9 | +Create a focused SSMS demo that: |
| 10 | +1. Creates a temporal table (with history table) |
| 11 | +2. Runs INSERT/UPDATE/DELETE to build up history |
| 12 | +3. Queries history using all FOR SYSTEM_TIME variants |
| 13 | +4. Runs in Azure SQL |
| 14 | +5. Fits in ~8 minutes of presentation time |
| 15 | + |
| 16 | +## FOR SYSTEM_TIME Variants to Cover |
| 17 | +- AS OF — point-in-time snapshot |
| 18 | +- FROM … TO — exclusive range |
| 19 | +- BETWEEN … AND — inclusive range |
| 20 | +- CONTAINED IN — fully within range |
| 21 | +- ALL — entire history including current |
| 22 | + |
| 23 | +## Slide Reference |
| 24 | +- Slide: "SELECT * FROM DemoTable FOR SYSTEM_TIME BETWEEN '2022-08-05' AND '2022-08-06' WHERE Id = 123 ORDER BY ValidFrom" |
| 25 | +- ValidFrom / ValidTo columns are system-managed |
| 26 | +- History table stores all previous versions |
| 27 | + |
| 28 | +## Learnings |
| 29 | + |
| 30 | +### 2025-01-27: Analyzed Existing SQL Demo Scripts |
| 31 | +**Task:** Reviewed all 14 .sql files in Demos\SQLDemo\ to inform new demo design |
| 32 | + |
| 33 | +**Key Findings:** |
| 34 | +- Existing demos use 3 different domains (Department, CompanyLocation, Inventory) — creates fragmentation |
| 35 | +- CRITICAL ISSUE: Hardcoded 2022 timestamps in query scripts won't work today |
| 36 | +- 14 files is too many for 8-minute demo; need to focus on core concepts only |
| 37 | +- Best patterns identified: HIDDEN period columns, WAITFOR DELAY for building history, comprehensive FOR SYSTEM_TIME coverage |
| 38 | +- HIDDEN period syntax keeps demo output clean: `ValidFrom DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL` |
| 39 | +- WAITFOR DELAY (2 seconds, used 2x = 4 seconds total) is acceptable for live demos |
| 40 | + |
| 41 | +**Recommendations Made:** |
| 42 | +- Use single domain throughout: Product (price tracking) or Employee (promotions/salary) |
| 43 | +- Create 3-script structure: Setup → Build History → Query History |
| 44 | +- Hybrid timestamp approach: WAITFOR DELAY + copy actual timestamps from output for precise queries |
| 45 | +- Keep scripts under 8 minutes total with presenter narration during delays |
| 46 | + |
| 47 | +**Decision Point for Team:** |
| 48 | +- Domain choice: Product vs Employee vs Inventory |
| 49 | +- Timestamp strategy: Hybrid (WAITFOR + copy) vs fully dynamic |
| 50 | +- Scope: Core 3 scripts vs optional 4th advanced script |
| 51 | + |
| 52 | +**Analysis Written To:** `.squad/decisions/inbox/marty-existing-demo-analysis.md` |
| 53 | + |
| 54 | +### 2025-01-27: Built SQLDemoFast — Complete 2-Minute SQL Temporal Demo |
| 55 | +**Task:** Implemented Doc's fast demo plan with Employee domain, pre-seeded history, and 3-script structure |
| 56 | + |
| 57 | +**Files Created:** |
| 58 | +1. `01-Setup.sql` — Creates Employee temporal table, inserts 4 current employees, pre-seeds history with hardcoded timestamps |
| 59 | +2. `02-Observe.sql` — Live DML (UPDATE Alice's salary, DELETE David), shows history accumulating with WAITFOR DELAY |
| 60 | +3. `03-TimeTravel.sql` — Time-travel queries (AS OF, BETWEEN, ALL) using pre-seeded timestamps |
| 61 | +4. Terraform infrastructure (main.tf, variables.tf, outputs.tf, terraform.tfvars.example) |
| 62 | +5. Complete documentation (2 README files: demo guide + Terraform deployment) |
| 63 | + |
| 64 | +**Key Design Decisions:** |
| 65 | +- **Domain: Employee** (per Doc's plan) — More compelling for DBA/developer audience than Product pricing |
| 66 | + - Schema: EmployeeId, EmployeeName, JobTitle, Department, Salary |
| 67 | + - Story: Alice (Developer → Senior Developer), Bob (Senior PM → Product Manager), Carol (Intern → Junior Developer), David (hired then deleted) |
| 68 | +- **Hybrid History Strategy**: Pre-seeded history (for reliable query demos) + live DML (for "wow factor") |
| 69 | + - Pre-seed technique: Turn off versioning, INSERT into history table with hardcoded timestamps, turn versioning back on |
| 70 | + - Hardcoded timestamps: 2024-01-15, 2024-04-01, 2024-06-15, 2024-07-01, 2024-09-01 |
| 71 | +- **Query Coverage**: AS OF, BETWEEN, ALL (skipped FROM...TO and CONTAINED IN per Doc's plan — too nuanced for 2-minute demo) |
| 72 | +- **WAITFOR DELAY**: 2 seconds × 2 = 4 seconds total (acceptable for live demo, creates temporal separation) |
| 73 | +- **HIDDEN Period Columns**: ValidFrom/ValidTo not shown in SELECT * (cleaner presenter output) |
| 74 | + |
| 75 | +**T-SQL Techniques Applied:** |
| 76 | +- System versioning on/off toggle for manual history manipulation |
| 77 | +- Explicit column lists when inserting into history table (ValidFrom/ValidTo required) |
| 78 | +- GO separators for batch control in SSMS |
| 79 | +- Comments written at presentation-quality (audience will read them on projector) |
| 80 | + |
| 81 | +**Terraform Configuration:** |
| 82 | +- Azure SQL Server (version 12.0) with globally unique naming |
| 83 | +- Database: TemporalDemo, SKU S0 (affordable for demos) |
| 84 | +- Firewall rules: Azure services + presenter IP |
| 85 | +- Variables validated (IP format, password complexity, server name constraints) |
| 86 | +- Outputs: FQDN, connection string (sensitive), SSMS connection info |
| 87 | + |
| 88 | +**Azure SQL Compatibility Notes:** |
| 89 | +- CREATE DATABASE is provisioned by Terraform (not in script) |
| 90 | +- Scripts use `USE TemporalDemo` to connect |
| 91 | +- All temporal table syntax identical to on-prem SQL Server 2016+ |
| 92 | +- UTC timestamps (added note in comments) |
| 93 | + |
| 94 | +**Documentation Quality:** |
| 95 | +- README.md: Complete presenter guide with timing, talking points, troubleshooting, Q&A prep |
| 96 | +- terraform/README.md: Step-by-step deployment with error handling and security notes |
| 97 | +- Inline SQL comments: Explain WHY not just WHAT (presentation-ready) |
| 98 | +- Mapped demo sections to slide concepts for alignment |
| 99 | + |
| 100 | +**Timing:** |
| 101 | +- 01-Setup.sql: ~20 seconds |
| 102 | +- 02-Observe.sql: ~40 seconds (includes 4 seconds WAITFOR) |
| 103 | +- 03-TimeTravel.sql: ~40 seconds |
| 104 | +- Total: ~2 minutes with narration |
| 105 | + |
| 106 | +**Learnings:** |
| 107 | +- **Pre-seeding history is essential** for demos with time-travel queries — removes dependency on "copy timestamp from previous run" |
| 108 | +- **Employee domain > Product domain** for this audience — human stories (promotions, departures) more compelling than price changes |
| 109 | +- **HIDDEN columns are critical** for presenter experience — keeps output clean without manually excluding ValidFrom/ValidTo |
| 110 | +- **Hybrid approach works best**: Pre-seed for reliable queries, live DML for audience engagement |
| 111 | +- **Comments matter in live demos**: These aren't just code comments, they're presenter notes and audience reading material |
| 112 | + |
| 113 | +**Decisions Written To:** `.squad/decisions/inbox/marty-sqldemofast-decisions.md` |
0 commit comments