SQLite Forum

history keeping
Login
By the answers I'm not sure whether my first post was all that clear. 

Second attempt; The example below may not be flawless, just to show what I was thinking. The 'old' row is copied to a new test_id and references the old_test_id that is also in use in other tables. Now the 'old' row can be updated with new content.
Query for an "id" in historic gives all previous versions, sort by ts_eol.
For current version create an index (test_id, ts_eol is Null)

```
CREATE TABLE test(
    test_id INTEGER PRIMARY KEY NOT NULL
    content TEXT NOT NULL
    historic INTEGER DEFAULT NULL REFERENCES test(test_id)
    ts_from TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ts_eol TEXT DEFAULT NULL,
);

CREATE TRIGGER IF NOT EXISTS update_test
BEFORE UPDATE OF content ON test
BEGIN  
    INSERT INTO test (content, historic, ts_from, ts_eol)
    SELECT old.content, old.test_id, old.ts_from, CURRENT_TIMESTAMP
    ;
END
;
```