Ready, SET, go – how does SQL server handle recursive CTE’s

Posted on Posted in Database, Development, Performance, Script, SQL 2012, SQL 2014, SQL 2016, T-SQL

stairs

First of all, a quick recap on what a recursive query is.

Recursive queries are useful when building hierarchies, traverse datasets and generate arbitrary rowsets etc. The recursive part (simply) means joining a rowset with itself an arbitrary number of times.

A recursive query is defined by an anchor set (the base rowset of the recursion) and a recursive part (the operation that should be done over the previous rowset).

This blogpost will cover some of the basics in recursive CTE’s and explain the approach done by the SQL Server engine.

The basics

A recursive query helps in a lot of scenarios. For instance, where a dataset is built as a parent-child relationship and the requirement is to “unfold” this dataset and show the hierarchy in a ragged format.

Read the full blogpost HERE.

 

Gem

Leave a Reply

Your email address will not be published. Required fields are marked *