In a recursive CTE written as a seed query unioned with a recursive term, what ends the recursion?
Correct answer
A. The recursive term returning no new rows, which stops the iteration
19 views
A. The recursive term returning no new rows, which stops the iteration
19 views
A recursive CTE evaluates the seed, then repeatedly applies the recursive term to the rows produced by the previous iteration, stopping when an iteration returns no rows. UNION ALL keeps duplicates, so a cycle in the data recurses forever unless the query tracks visited keys. Some engines allow an iteration cap as a hint, but the standard mechanism is the empty step.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.