Tools worth exploring
SQLite: when does a project outgrow one table file?
Store AI workflow results in SQLite with constraints, relationships and transactions, keeping model text out of executable SQL and avoiding row-count myths.

Relations matter more than a magic row count
A database becomes useful for relationships, constraints and repeated queries rather than a universal row-count threshold. Repeating customer names and addresses in orders creates inconsistent updates; reference a customer ID instead.
Link orders to stable customer IDs
This in-memory SQLite example creates two tables and joins them. Explicit foreign-key enforcement rejects references to missing customers. Set it for the connection before transactions rather than assuming it is already enabled.
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("PRAGMA foreign_keys = ON")
con.executescript("""
CREATE TABLE customers(id INTEGER PRIMARY KEY, name TEXT NOT NULL);
CREATE TABLE orders(id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(id));
INSERT INTO customers VALUES(1, 'Mira');
INSERT INTO orders VALUES(17, 1);
""")
print(con.execute("SELECT orders.id, customers.name FROM orders JOIN customers ON orders.customer_id=customers.id").fetchall())
con.close()[(17, 'Mira')]; the in-memory database disappears when the connection closes.
Download example text ↓Enforce the constraints explicitly
Choose money representation deliberately, such as integer minor units where appropriate. Suitability also depends on concurrency, backup and write patterns, not merely the ability to store a table.
Persist acceptance and event identity together
An extraction workflow can store event identity and accepted fields in one transaction so completion cannot exist without output. Define unique-key conflicts explicitly. Keep attempts linked to an event rather than overwriting approved output on every retry. Foreign-key enforcement is connection-specific; test rejection of an absent parent instead of assuming the constraint is active.
Pass user or extracted values as query parameters, not SQL string fragments. Dynamic identifiers need explicit allowlists, and model-generated free-form SQL should not gain unrestricted execution on a real database. Test storage failure, rollback and backup recovery. SQLite suitability follows access, concurrency and operational needs, not a magic threshold separating files from databases.
Sources & further reading
Sources support concepts and features; proposed trials are educational examples.
Prepared with AI assistance. Educational examples are not product tests; actual measurements identify their method and scope. Editorial approach ↗
Practice: verify SQLite relationships and event uniqueness
A fictional order system has two customers and three orders. The schema uses foreign keys and a unique external event ID. Unlike a loose CSV, it can reject a reference to a nonexistent customer.
Run the exercise
- Create an empty SQLite database, execute schema.sql followed by seed.sql, and run the grouped query in queries.sql.
- Compare result rows with expected-results.csv. Confirm the number of orders and totals for each customer.
- Run negative-tests.sql separately and expect constraint errors. Verify that PRAGMA foreign_keys=ON was enabled on the connection.
Reference outcome: Customer 1 has two orders totaling 50; customer 2 has one totaling 20. Bad customer IDs and duplicate external event IDs are rejected.
Limits: SQLite foreign key enforcement must be enabled per connection. The negative test is intentionally meant to fail; do not run it on a production database.
Download the exercise and reference files (ZIP)
Exercise added October 29, 2026. Fictional teaching cases, not external service test results.