Skip to content

Instantly share code, notes, and snippets.

@thewiredbear
thewiredbear / pure_sql_scd_update.sql
Created January 16, 2026 00:14 — forked from raven-rock/pure_sql_scd_update.sql
"Pure SQL" algorithm for updating of slowly changing dimension (SCD Type 2) table records with just two DML statements (SQLite example)
-- SQLite
-- Test: sqlite3 -header -echo -column :memory: < %
create table t1 (
bk int
, valid_from datetime default CURRENT_TIMESTAMP
, valid_to datetime default '9999-12-31 23:59:59'
, a1 varchar(20)
, primary key (bk, valid_from)
);