The snippet library.
Small, practical examples. Search by task or narrow things down below.
Add an optional field to an existing table
SQLite: A nullable column permits existing rows to remain valid while data is filled later.
SQLite✓ Tested
Commit multiple related changes together
SQLite: The first transaction prepares the fixtures. The second commits both updates as one unit.
SQLite✓ Tested
Create an index for an equality filter
SQLite: A nonunique index can support lookups on a frequently filtered column.
SQLite✓ Tested
Create an index matching filter and ordering columns
SQLite: Place the equality-filter column before the ordering column in this composite index.
SQLite✓ Tested
Enforce a relationship between two columns
SQLite: A row-level CHECK can require a start value to be no greater than an end value.
SQLite✓ Tested
Enforce uniqueness with a dedicated index
SQLite: A unique index rejects a duplicate combination independently of query plans.
SQLite✓ Tested
Expose a reusable filtered view
SQLite: A view stores a query definition rather than a snapshot of its rows.
SQLite✓ Tested
Read updated base-table values through a view
SQLite: An ordinary view reflects later changes to its underlying data.
SQLite✓ Tested
Undo a multi-row transfer atomically
SQLite: The first transaction commits the fixtures. Rolling back the second transaction restores both sides of the attempted transfer.
SQLite✓ Tested
Undo only the work after a savepoint
SQLite: After committing the fixtures, roll back a trial change while keeping earlier work in the second transaction.
SQLite✓ Tested