Menu

Your incremental load is quietly losing rows, and the IDENTITY column is why
📰

Your incremental load is quietly losing rows, and the IDENTITY column is why

DEV Community: sql·Isaac Tonyloi - SWE·9 days ago
#2rrnUmVY
#devtosql#devto#dev#load#journalentryid
Long article (1757 words) — no AI summary yet.
Reading 0:00
15s threshold

Most incremental loads I've seen are built on one line.

WHERE Id > @LastLoadedId

Enter fullscreen mode

Exit fullscreen mode

It's fast, it's easy to explain, and it passes every test you're likely to write. On a busy database it also drops rows now and then, with no error and no warning. The fact table just ends up slightly short, and nobody notices until finance asks why the warehouse and the ledger disagree by 500.00.

I wanted to see this happen rather than take it on faith, so I reproduced it on a double-entry ledger I've been building in SQL Server for a savings and credit co-op. This post walks through the reproduction, explains why it happens, and shows the fix I ended up using.

The setup

The source is an append-only ledger. Every money movement is a row in JournalEntry with two or more rows in JournalLine . Nothing is ever updated or deleted, so it looks like the easiest possible table to load incrementally.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.