Looping

  • Thank you very much for your apprication mate.

  • sam.dahl (3/15/2012)

    At the end of running the code and after stopping the execution my transaction remains open.

    If I then commit the transaction I get the result you described.

    However if I roll it back I don't get any records.

    I agree, the correct answer isn't entirely correct. Not to mention the issues that could arise from having a runaway script with an open transaction...

  • Nice easy question. Unfortunately the choices are worded such that none of them are really correct. The biggest issue is this is testing syntax on a construct that we strive so hard around here to convince people not to use. If this was a forum post everyone would be asking "why do you need a loop for this? This is a set based operation.".

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thanks for the easy question!

  • For those who say that an error is built into the code because it will fill up the disk, which in the real world is true, step back a second and think about the logic in isolation. Pretend it is like a Turing machine with unlimited capacity. If you execute that code without any physical limits, there will be no error. There is no syntax preventing the execution of the code. If disk space weren't an issue, that could would in fact go on forever without a specified limit. So if you look at this strictly as a syntax issue, the question is sound.

  • jeff.mason (3/16/2012)


    So if you look at this strictly as a syntax issue, the question is sound.

    A fair point. Depends whether you thought (rightly) that the question was about forgetting to increment the counter; or thought (wrongly) that it was about log files filling up. Guess which I went for 🙁

  • nice one 😎

  • Thanks for the question, made me think a little because of the code being within a TRANsaction.

    My opinion is that the code was created with looping logic code in mind, not logging/replication or anything like that. We know for sure that this code will eventually fill up ANY server's disk space, but I think that was not the point of the question.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Toreador (3/16/2012)


    jeff.mason (3/16/2012)


    So if you look at this strictly as a syntax issue, the question is sound.

    A fair point. Depends whether you thought (rightly) that the question was about forgetting to increment the counter; or thought (wrongly) that it was about log files filling up. Guess which I went for 🙁

    Well, the title of the question WAS looping. And if you think about it, intuitively the correct option is what you expect from the looping behavior.

  • Took me all of 5 seconds: thanks!

  • Sean Lange (3/16/2012)


    Nice easy question. Unfortunately the choices are worded such that none of them are really correct. The biggest issue is this is testing syntax on a construct that we strive so hard around here to convince people not to use. If this was a forum post everyone would be asking "why do you need a loop for this? This is a set based operation.".

    I've always wondered why T-SQL is so bad at loops. Is there an inherent limitation on the quality of program translation inside T-SQL that forces such bad performance? I always just considerd that it could be another shortcoming with Microsoft, but I also have wondered if there are circumstances that require poor performance with language translation inside SQL server.

  • nice easy one to round out the week - cheers

  • I'm glad for a developer question, finally... 😀

    This is what I've called for forty years an infinite loop.

    Infinite loops are one of many programming pitfalls that one learns about in school and in practice. It was obvious to me the author intended the question to be about infinite loops. Having a QotD that is obvious to me is a rarity.

    In the real world, disk would eventually fill up and some sort of error would be issued. From a purely theoretical and "book learnin'" viewpoint, the loop is infinite.

    Thanks for the question.

  • I wonder if this was put in to catch the people who answer by just running the script without trying to understand it? Let's hope nobody tried that on a production system... 😛

  • happycat59 (3/15/2012)


    Whilst it might take a while, eventually you will get an error when you run out of disk space. So, I kinda think that the correct answer is most likely that you will get an error at line 8 (the INSERT statement).

    That may be true, but given the max size limitations of SQL Server and if you could have that much disk space - you would be waiting for a very very very long time.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 15 posts - 16 through 30 (of 49 total)

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