FIND YOUR NEXT FEW LINES

Results for “SQL”

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

500 snippets foundClear filters
PostgresSchema design & transactions

Read updated base-table values through a view

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

Postgres✓ Tested
SQLiteTables & writes

Read values from an inserted row

Use RETURNING to retrieve an automatically assigned row ID.

RETURNING✓ Tested
SQL ServerJSON & results

Read values generated by INSERT

Capture an IDENTITY value with OUTPUT.

OUTPUT✓ Tested
PostgresConstraints & defaults

Reference a parent identified by two columns

Postgres: A composite foreign key checks the complete referenced key rather than either column independently.

Postgres✓ Tested
PostgresConstraints & defaults

Reject a negative quantity with CHECK

Postgres: Combine NOT NULL and CHECK because an unknown NULL check result is normally accepted.

Postgres✓ Tested
PostgresConstraints & defaults

Reject duplicate business identifiers

Postgres: A UNIQUE constraint protects a business key independently of the primary key.

Postgres✓ Tested
PostgresConstraints & defaults

Remove dependent rows with a declared cascade

Postgres: ON DELETE CASCADE removes children when their referenced parent is deleted.

Postgres✓ Tested
PostgresGetting Started

Remove duplicate result values

Postgres: Use DISTINCT when repeated category values are not useful.

Postgres✓ Tested
PostgresBulk changes & set operations

Remove duplicate values while keeping the smallest key

Postgres: Identify retained keys in a grouped subquery before deleting other copies.

Postgres✓ Tested
PostgresText cleanup & matching

Remove surrounding spaces from text

Postgres: TRIM removes leading and trailing space characters by default.

Postgres✓ Tested
PostgresWindow analytics

Repeat the first ordered value beside each row

Postgres: FIRST_VALUE reads the first value in the current window frame.

Postgres✓ Tested
PostgresText cleanup & matching

Replace a literal substring

Postgres: REPLACE performs a literal replacement rather than a regular-expression substitution.

Postgres✓ Tested