Bird
0
0

Given a recursive CTE that calculates the total salary budget per manager including all subordinates, which additional SQL feature is essential to avoid infinite loops in case of circular references?

hard📝 Application Q9 of 15
SQL - Common Table Expressions (CTEs)
Given a recursive CTE that calculates the total salary budget per manager including all subordinates, which additional SQL feature is essential to avoid infinite loops in case of circular references?
AUsing DISTINCT in the recursive member
BUsing GROUP BY in the anchor member
CAdding ORDER BY in the final SELECT
DA termination condition limiting recursion depth
Step-by-Step Solution
Solution:
  1. Step 1: Understand circular reference risk

    If employees reference each other as managers in a loop, recursion can run infinitely.
  2. Step 2: Use termination condition

    Limiting recursion depth or adding conditions to stop recursion prevents infinite loops.
  3. Final Answer:

    A termination condition limiting recursion depth -> Option D
  4. Quick Check:

    Prevent infinite recursion with termination condition [OK]
Quick Trick: Limit recursion depth to avoid infinite loops [OK]
Common Mistakes:
  • Relying on DISTINCT to fix loops
  • Adding ORDER BY which doesn't stop recursion
  • Using GROUP BY in anchor member incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes