0PricingLogin
SQL Academy · Lesson

Temporal and Versioned Rows

Valid-time and as-of queries.

What Are Temporal Tables?

Temporal tables let you track how data changes over time. Instead of overwriting a row when something changes, a temporal table keeps every version of that row, each tagged with the time period it was valid.

There are two key concepts: valid time (when the fact was true in the real world) and transaction time (when the database recorded the fact). Combining both gives you a fully bi-temporal table.

Valid Time vs. Transaction Time

Valid time represents when a fact is true in the real world — for example, an employee's salary from 2020-01-01 to 2022-06-30. Transaction time is when the database row was inserted or expired. Together they answer two questions: What was true? and When did we know it?

Most practical use cases start with valid-time tracking, which you can implement manually using valid_from and valid_to columns.

All lessons in this course

  1. Why Keep History
  2. Append-Only Event Tables
  3. Temporal and Versioned Rows
  4. Rebuilding State from Events
← Back to SQL Academy