SQL guides
Every published SQL guide, newest first, with practical examples you can copy into your own project.
3,815 guides across 14 topics
Topics
Popular SQL guides
Most readLatest SQL guides
Page 1 of 2SQL Cursors vs Set-Based Operations: Syntax, Memory, and Performance
Why a row-by-row cursor costs minutes where one UPDATE takes seconds, how server cursors spool to disk, and the set-based replacements for each loop.
SQL Date and Time Functions: INTERVAL Arithmetic, Time Zones, and DST
timestamptz versus timestamp, half-open ranges that keep an index, and the daylight saving gaps that make local scheduling wrong once a year.
SQL Row Locking: SELECT FOR UPDATE, SKIP LOCKED, and NOWAIT
How FOR UPDATE locks rows until commit, why the plan decides the lock scope, and the SKIP LOCKED claim-queue pattern that scales to many workers.
SQL String Functions: CONCAT, SUBSTRING, REPLACE, and Pattern Matching
The concatenation and slice functions that differ between engines, why LIKE 'x%' uses an index and '%x%' cannot, plus escaping and NULL rules.
SQL JSON and JSONB: Functions, Operators, and Indexing Strategies
Why jsonb is the default for queryable documents, when containment can use a GIN index, and the expression-index fixes for scalar lookups.
SQL PIVOT and UNPIVOT: Row-to-Column and Column-to-Row Data Transformation
The literal column list, the NULL rows that UNPIVOT drops, and the type coercion that turns dates into strings — plus the portable FILTER form.
SQL EXPLAIN and EXPLAIN ANALYZE: Reading Query Execution Plans for Optimization
Estimated rows versus actual rows is the whole game: reading plans, multiplying by loops, interpreting buffers, and fixing the statistics first.
SQL Triggers: BEFORE, AFTER, INSTEAD OF Syntax and Common Pitfalls
A BEFORE trigger that returns NULL deletes the row without an error, bulk updates fire it once per row, and TRUNCATE skips it entirely.
SQL Stored Procedures vs Functions: Syntax, Parameters, and Execution Differences
Procedures act, functions compute: transaction control, IN/OUT parameters, volatility that lies, and the plan caching that makes procedures slow.
SQL Views vs Materialized Views: Syntax, Refresh Strategies, and Performance
Why a view is inlined into your query while a materialized view is a cached table, how CONCURRENTLY refreshes work, and the RLS trap hidden in views.