RECURSIVE is used inside a WITH clause to declare a recursive CTE. A recursive CTE has two parts: an anchor query that returns the base result set and a recursive query that references the CTE itself. The database repeatedly executes the recursive query, adding rows to the interim result until no new rows are produced, then returns the combined set. Depth-first or breadth-first evaluation order is implementation-specific, and most engines automatically prevent infinite loops by tracking previously returned rows. Performance depends on proper indexing and termination conditions. In ANSI SQL:1999, RECURSIVE became part of the standard; today it is widely supported but syntax details vary slightly by vendor.
WITH, CTE, UNION ALL, WINDOW FUNCTIONS, HIERARCHICAL QUERY (CONNECT BY)
ANSI SQL:1999 (recursive query), first implemented in PostgreSQL 8.4
It simplifies hierarchical queries, sequence generation, and iterative calculations that would otherwise need procedural code.
Yes. Recursive CTEs were added in ANSI SQL:1999 and are now broadly supported.
Most databases let you add a WHERE clause on a level column or set engine-specific limits (e.g., SET max_recursion_depth in SQL Server).
Index the join columns, use UNION ALL, and return only needed columns to minimize work during each recursion step.