FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
SQLSchema design & transactions

Add an optional field to an existing table

SQL: A nullable column permits existing rows to remain valid while data is filled later.

SQL✓ Tested
SQLSchema design & transactions

Commit multiple related changes together

SQL: The first transaction prepares the fixtures. The second commits both updates as one unit.

SQL✓ Tested
SQLSchema design & transactions

Create an index for an equality filter

SQL: A nonunique index can support lookups on a frequently filtered column.

SQL✓ Tested
SQLSchema design & transactions

Create an index matching filter and ordering columns

SQL: Place the equality-filter column before the ordering column in this composite index.

SQL✓ Tested
SQLSchema design & transactions

Enforce a relationship between two columns

SQL: A row-level CHECK can require a start value to be no greater than an end value.

SQL✓ Tested
SQLSchema design & transactions

Enforce uniqueness with a dedicated index

SQL: A unique index rejects a duplicate combination independently of query plans.

SQL✓ Tested
SQLSchema design & transactions

Expose a reusable filtered view

SQL: A view stores a query definition rather than a snapshot of its rows.

SQL✓ Tested
SQLSchema design & transactions

Read updated base-table values through a view

SQL: An ordinary view reflects later changes to its underlying data.

SQL✓ Tested
SQLSchema design & transactions

Undo a multi-row transfer atomically

SQL: The first transaction commits the fixtures. Rolling back the second transaction restores both sides of the attempted transfer.

SQL✓ Tested
SQLSchema design & transactions

Undo only the work after a savepoint

SQL: After committing the fixtures, roll back a trial change while keeping earlier work in the second transaction.

SQL✓ Tested