What is recursion?

  • Based on this thread it sounds as if you are dealing with a recursive CTE and I think you've received pretty good input.

    With respect to SQL Server the only benefit I've seen to understanding recursion is that you can troubleshoot someone else's poorly performing code. If you ever get into functional programming (the article Sean posted makes mention of this) understanding recursion is important because functional programming languages are optimized for recursion.

    Outside of that I think it's a cool mathematical concept.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • I did a quick search and looked through a few links on recursion. Here is one that I think explains the basics fairly well from a elementary standpoint.

    http://www.cplusplus.com/articles/D2N36Up4/

    ----------------------------------------------------

  • As I see it Recursion in T-SQL is like paying taxes, something we would all like to avoid but some(read most)times that's not possible.

    😎

  • To answer the original question; this

    http://qa.sqlservercentral.com/Forums/Topic1752249-1292-1.aspx

    is recursion.

  • Chris Wooding (1/21/2016)


    To answer the original question; this

    http://qa.sqlservercentral.com/Forums/Topic1752249-1292-1.aspx

    is recursion.

    I would also call that an infinite loop. A Recursive function should have a cut off point. 😛

    ----------------------------------------------------

  • MMartin1 (1/21/2016)


    Chris Wooding (1/21/2016)


    To answer the original question; this

    http://qa.sqlservercentral.com/Forums/Topic1752249-1292-1.aspx

    is recursion.

    I would also call that an infinite loop. A Recursive function should have a cut off point. 😛

    There is one, when you get tired of being redirected to the same place over and over.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • The key question of recursion is in which cases is it the best approach ?

    I remember the infamous factorial example - convenient to use to explain recursion in this very simple case. But often no warning given that this is the most inefficient way of calculating factorials. In fact, given the overhead involved, it is downright stupid to use recursion for factorials.

    So when is the overhead warranted ?

Viewing 7 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply