Creating Tables

  • I really wasn't sure if I have to 'GO' or not to 'GO' for my answer...I GOed and got it right..So what I learned from this Qotd is whenever there is a doubt just keep GOing 😉

    ___________________________________________________________________
    If I can answer a question then anyone can answer it..trying to reverse the logic.. :hehe:

  • (Bob Brown) (2/11/2013)


    Sean Lange (2/11/2013)


    Here is the original code with the GOs commented out so it will be a single batch.

    But the GOs are there.

    Even if you ignore the erroneous use of the word 'batch' in the question and leave the GOs in place... the third answer is still not correct because it says that only statements 1 and 3 will run successfully, which is not the case.

    It's unfortunate because the wording issues are confusing and distract from the intent of the question.

  • sestell1 (2/11/2013)


    Even if you ignore the erroneous use of the word 'batch' in the question and leave the GOs in place... the third answer is still not correct because it says that only statements 1 and 3 will run successfully, which is not the case.

    It's unfortunate because the wording issues are confusing and distract from the intent of the question.

    I agree! A truce?

  • I saw that the the CREATE TABLE and INSERT INTO #Table would conflict therfore running it as one batch (as stated in the Question) would error the whole statement regardless of the GO commands being there or not being there.

    The results are the same if you run the whole query as one batch with or without the 'GO' commands.

    Therfore the Answer

    [Quote]

    Only the 1st and 3rd statement will succeed but no rows will be returned.

    [/Quote]

    is wrong!

    And the Correct answer should be.

    [Quote]

    All statements will fail.

    [/Quote]

    If You run the whole query as 1 Batch (as stated!)

    If however, you were asked to run the three independantly in the same Query window then the right answer would be.

    [Quote]

    Only the 1st and 3rd statement will succeed but no rows will be returned.

    [/Quote]

    Poorly wrote question and needs correcting. (oh and give me the point for a correct answer :-D:-P)

    Regards
    ld

    Stoke-on-Trent
    United Kingdom

    If at first you don't succeed, go to the pub and drink away your current thought plan.

  • I have been reading the QODs as of late with a grain of salt. If the wording is correct there is one answer, but given the wording of some of the questions and guessing on the intent the answer is not always as it appears. I guessed at the answer and in doing so I made an assumption.

    I assumed that the author was saying "what happens if you include all of the SQL in a batch job or a scheduled script run as a batch job?" THis gives a second meaning to the word batch and made the correct answer correct.

    However, I have to agree that GO denotes a batch execution of all previous unexecuted SQL, that is just how it is done. Multiple Go statements are by definition multiple batch executions. If you remove all but the last Go there is a different answer.

    But I have to admit that this line of discussion to a rookie, ( and we were all rookies at one time), this discussion is very valuable and educational.

    M.

    Not all gray hairs are Dinosaurs!

  • ldorian81 (2/11/2013)


    If you put the whole query into SSMS 2008 and run it without removing the 'GO' commands you will still get the same results as shown below.

    Msg 2714, Level 16, State 1, Line 18

    There is already an object named '#TempQoD' in the database.

    .

    That appears on the messages tab. The results tab had the table selected with no rows.

  • I made the assumption that the author didn't actually understand that GO was a batch separator and was instead focused on the temp table creation process. I hate to make these assumptions but I couldn't see why they would write to run it as one batch when one could not do so without modifying the code supplied. Another flawed QoTD. Thanks for trying.

  • Wording was confusing, however I managed to get it right.

    Saludos,

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

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

  • Since the question didn't ask what version of SQL Server, none of the answers are correct. In SQL 2005, you get an error message, yet you still get one row selected.

    Msg 2715, Level 16, State 7, Line 2

    Column, parameter, or variable #4: Cannot find data type Date.

  • I thought the question was straight forward and got that correct. Thanks 🙂

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • Statistics so far:

    ---Number of attempted answers: 880

    ---Number of correct answers: 587 (67%)

    ---Number of incorrect answers: 293 (33%)

    ---Number of discussion posts: 39

    ---Number of positive and/or educational posts: 28 (72%)

    ---Number of negative and/or whining posts: 11 (28%)

    Isn't it interesting there is a correlation within 5% of correct answers to positive posts and incorrect answers to whining posts. :w00t:

    Enjoy!

  • Dave62 (2/12/2013)


    Isn't it interesting there is a correlation within 5% of correct answers to positive posts and incorrect answers to whining posts. :w00t:

    No, I don't find that interesting at all.

    I also don't see the point of having a single bucket for "positive and/or educational".

    In my opinion, positive posts ("great question!"), negative posts ("you suck!") and whining posts ("give me my point") are all an utter waste of bandwith, and I suspect most of the people who regularly write posts like that of doing it for the sole purpose of accumulating points. I hate it when I get mails from twnety different QotD discussions I am subscribed to, all within thrigy minutes, all because of a post from the same poster, and all contributing nothing but "good question", "got it right", "missed it", or whatever.

    Posts that are useful are what you probably label "educational". Those include obviously posts that give (extra) information, but also posts that ask for more information, for an explanation, or for a clarification - those posts in themselves don't educate, but they (hopefully) trigger a response that WILL add information to the topic.

    Then again - a post that adds information that has already been added a dozen times in the same topic would, in my opinion, again qualify as waste of bandwidth.

    (I also can't help wondering how you would qualify your own post. Or my response to it in this post. My qualification would be "waste of bandwidth", for I don't really see how discussing statistics of posts adds value that is relevant for the average SQL Server Central visitor.)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (2/12/2013)


    No, I don't find that interesting at all. ...

    Well of course we are all entitled to our own opinion of what is interesting.

    (I also can't help wondering how you would qualify your own post. Or my response to it in this post. My qualification would be "waste of bandwidth", for I don't really see how discussing statistics of posts adds value that is relevant for the average SQL Server Central visitor.)

    Again, we are all entitled to our own opinion of what may be relevant to people who use SQL Server. I would think some DBA's may find a discussion of statistical analysis interesting and/or relevant and of course some will not.

    I guess you are free to make posts that you qualify as a "waste of bandwidth" but I must say that a large majority of your posts I find educational. Thank you for your contributions.

    Enjoy!

  • I often work with product owners who write requirements with very similar logic and wording. 😉

    Thanks for the question!

  • Hugo Kornelis (2/12/2013)


    I also don't see the point of having a single bucket for "positive and/or educational".

    One common purpose of combining two things into a single bucket is to create an impression that these two things are closely associated. It's an extremely common practise amongst PR people. But Dave is presumably a DBA not a PR hack so I don't imagine his purpose of doing it was that. Probably it was just a rather silly (because it might cause people to think that he was trying to create associations between disagreeing with him and whining and between agreeing with him and being educational) means of reducing the number of buckets. Anyway, his arithmetic is wrong, since the educational posts are mostly negative and should be in both buckets so that the percentages should sum to more than 100%, but he has them sum to 100%. When wearing my mathematician hat I used to hate it when people got careless like that with numerical data, but these days I no longer worry about it, just point it out when it seems appropriate to do so.

    Tom

Viewing 15 posts - 31 through 45 (of 58 total)

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