Rowcount

  • This is a poorly worded question.

    It does not state the conditions of the question.

    Tried it on my 2000 server.

    Opened a Query Analyzer window.

    Entered both lines.

    Pressed F5 to run.

    I got 0,1

    All subsequent runs give 1,1

    If I save the two select statements into a sql script. Close Query Analyzer. Open Query Analyzer. Open and execute the script. I get 0,1.

    This is a poorly worded question.

    When I first looked at the question, my assumption was that we were in a fresh environment/session and that nothing else had been run.

    If I had just run a query prior to executing these two lines, the first select would have returned the rowcount from that query. Thus I assumed that the question implied that nothing had been run prior to the first select.

  • Wow, so many replies - I'd chime in and say the answer is:

    NULL

    Reason:

    The previous statement is unknown, therefore the outcome of the first SELECT @@ROWCOUNT is unknown, therefore the whole answer to this question is unknown.

    Q.E.D.

    😀

    Edit: For the posters STILL complaining that 1,1 should be the result or 0,1 should be the result:

    Read the whole thread, especially the posts about the trace (profiler) you can use to identify the last statements that were executed by your tool of choice (SSMS, sqlcmd, osql, QA or else) upon connection. There will almost always be at least one statement affecting @@ROWCOUNT (see msdn link for statements that affect @@ROWCOUNT) and the last one will be determining the results you get in your specific case.

    Best Regards,

    Chris Büttner

  • bitbucket-25253 (1/29/2010)


    malleswarareddy_m The question is improper

    Rick-153145 Another rubbish QoTD.

    bluesbiker I agree with user "malleswarareddy_m", this question is improper

    To malleswarareddy_m, Rick-153145 and bluesbiker let me issue you a challenge.

    Each of you submit a QOD and lets see how well you do

    [/size]

    I agree with:

    kaspencer So, if you are considering writing a QotD, just remember: you are under a definite obligation to ensure that the answer is predictable and will be produced on the vast majority of instances and versions (unless conditions are specifically mentioned).

    Having submitted 25 QODs, 22 of which have been published, 2 are scheduled for March and 1 pending let me state "It is not an easy task"

    I would add to kaspencer's statement, the following addition: test, test and test again your proposed submission before submitting. Let a few days pass and retest, retest and retest to discover, if any, assumptions or unforseen events that might influence the correct answer(s)

    With all that said and done, the QOD did fullfill one prime goal -- It taught a lot of people something they did not know before.

    One step bitbucket forgot to mention - Have somebody review the question and offer suggestions too 😉

    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

  • Lynn Pettis (1/29/2010)


    Has the question been changed? I just answered it and it specified SQL Server 2005/2008, in a just opened connection (no other commands run).

    I was surprised that it would return:

    1

    1

    when run.

    I ask the above, because from the comments it appears that it may have been updated.

    Significantly changed.

    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

  • It's a good QOD because it served it's purpose of educating some, and now everyone has their points. For those who haven't checked out @@ROWCOUNT in BOL, please do so.

    Note that the setting for NOCOUNT has no effect at all, it is the act of setting it that resets @@ROWCOUNT.

    SET NOCOUNT ON

    select @@ROWCOUNT

    SET NOCOUNT OFF

    select @@ROWCOUNT

    yields 0, 0.

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • sjimmo (1/29/2010)


    Chad - You got me thinking.

    I opened an OSQL session in DOS to a SS2K5 box, and running the code as is got the 0,1 answer.

    BUT - how many people would do that? How many answered based upon this vs using SSMS?

    You are exactly right - I would make that same assumption, and that is where this question falls short. When I first read the question, I didn't even think that the options I have set in SSMS would make a difference and answered based on what I saw when I ran the script (some call that cheating, but I thought about it first, then ran it to confirm - I call it "making full use of available resources" :-D. It usually works.). My guess is that Amit did the same - opened up a query window, ran the script, wrote the question (maybe testing with different versions too) and submitted it, not thinking that an option set in SSMS 4 years ago might have an impact on the outcome.

    Steve Jones - Editor (1/29/2010)


    The question has been changed. It was edited to say SS2K5 and the answer moved to 1,1. All points have been awarded back.

    I believe I tested this, but it was months ago. Likely I tested it on SS2K and it appeared to work. I would guess the author did the same thing.

    Steve - I don't think that fixes the issue. I saw the same result on SQL2K, 2K5 and 2K8 using SSMS - I don't think it is determined by the version, I think it is determined by the options you have set on the client. I'm guessing, but I believe that those who saw something different in SQL2K used Query Manager rather than SSMS, so they likely had different options set. Anyone with SET STATISTICS IO (or any one of a number of other settings) set as an option in their client will see 0,1 in a brand new query window. I'm not asking you to change anything, but we may get people complaining from the other side now. Hopefully fewer, since I think the default option settings in SSMS will end up returning 1,1.

    Christian Buettner-167247 (1/29/2010)


    Wow, so many replies - I'd chime in and say the answer is:

    NULL

    Reason:

    The previous statement is unknown, therefore the outcome of the first SELECT @@ROWCOUNT is unknown, therefore the whole answer to this question is unknown.

    Now THAT is funny! You get my vote! You'll keep me laughing all night...

    Chad

  • Hi,

    I didn't that this question is rubbish.Because there is no clarity for relation between question and answer.But this is an intresting topic.What is my intension is question sholud be Understandable.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • I'm not usually one to start an argument, but I have to say questions proving to have wrong or ambiguous answers to questions aren't the only trends i'm noticing at the moment. I find it extremely hard to believe that all the people who got it right got it right because they already knew it. I answered 0,1 because it was the logical answer given the knowledge i possess. Clearly it was wrong because as already mentioned earlier in the thread, a hidden value is returned that gives us the first 1, but I really don't think a large majority of the people replying here to the effect of 'i want my points back' deserve them if all they did was look at the question and then run the query and clicked the 'correct' answer.

    It seems to be happening more and more at the moment and it makes me wonder how many of the people who get the answer right in any QotD only get it right because they don't bother going with what they know or think they know and accept it when they get it wrong, and instead simply run the query and feed in the correct answer. Not much of a challenge to your knowledge if you don't even try and accept the consequences (no points) of getting it wrong

    Rant over, and it might not be a very popular opinion, i don't know, but I just had to say it

    Paul

  • paul.goldstraw (2/1/2010)


    It seems to be happening more and more at the moment and it makes me wonder how many of the people who get the answer right in any QotD only get it right because they don't bother going with what they know or think they know and accept it when they get it wrong, and instead simply run the query and feed in the correct answer. Not much of a challenge to your knowledge if you don't even try and accept the consequences (no points) of getting it wrong

    I agree. Theese who are running any script first before answering

    -don't like to play games

    -like more to obtain their points than to learn something

    -are swindlers a little

    -are lazy to use the thing between ears

    I think it's a game. A game that makes me more powerful over SQL Server. Points are not so important for me, my salary is independent on this number 🙂



    See, understand, learn, try, use efficient
    © Dr.Plch

  • Well, you got me - I confess - I cheated at least once in the QotDs.

    But that is probably true for most of us - sometimes we just cannot withstand - and nobody is hurt.

    But if one cheats and then at the same time complains in an intentionally rude tone - better not.

    Best Regards,

    Chris Büttner

  • Christian Buettner-167247 (2/1/2010)


    Well, you got me - I confess - I cheated at least once in the QotDs.

    But that is probably true for most of us - sometimes we just cannot withstand - and nobody is hurt.

    But if one cheats and then at the same time complains in an intentionally rude tone - better not.

    I confess, me to (once) 😀



    See, understand, learn, try, use efficient
    © Dr.Plch

  • it is depend on the last execution . So options for this question was wrong.

  • I think the answer is highly dependent on options, which makes it a poor question. It could appear to be one way or the other in many tests, until you had changed a particular options.

    Using defaults, which is what I have an instance set with, "1,1" seems to be what happens. We cannot list all options or settings for a client, so we have to use something, and defaults seem to make sense. If you've changed those, then we can't really account for that.

    As far as the last execution, the question now says a "new query window". There is no last execution in the client, other than the SETtings that may have been sent.

    I don't think this is a good question for knowledge because the way it works could vary widely. The original answer, "0,1" is what should theoretically be returned in a new query window with no previous execution, but you can't get to that point in a client without initiating a connection and executing something.

  • honza.mf

    paul.goldstraw (2/1/2010)

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

    It seems to be happening more and more at the moment and it makes me wonder how many of the people who get the answer right in any QotD only get it right because they don't bother going with what they know or think they know and accept it when they get it wrong, and instead simply run the query and feed in the correct answer. Not much of a challenge to your knowledge if you don't even try and accept the consequences (no points) of getting it wrong

    I think that the QOD has two equally valid values.

    1. To allow individuals to test their knowledge.

    2. To teach.

    For those who know the answer it is a re-assuring experience

    For those who do not know the answer, running the code teaches them something (at least I hope it does)

    Their always exists the legitimate complaint that the QOD author did in fact not specify sufficient information to justify the correct answer(s). And hopefully from the comments the author learns something. That ever present reminder "It all depends" and it teaches the author how better perform his/her job

    The unsettling part is for many(NOT all) who answer incorrectly, the quest is not for learning, but rather a blow to their ego, and that upsets them greatly. And they post their moans and groans demanding points, exposing their true nature.

    What we do not know is how many answer incorrectly, and do NOT post a moan and groan, but DO LEARN something which in the future will be of benefit to them.

    Just my two pennies worth.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • bitbucket-25253 (2/1/2010)


    I think that the QOD has two equally valid values.

    1. To allow individuals to test their knowledge.

    2. To teach.

    For those who know the answer it is a re-assuring experience

    For those who do not know the answer, running the code teaches them something (at least I hope it does)

    Nothing wrong with any of that, but for those who don't know the answer, should they be running the code before they answer, or after they have answered and got it wrong? I believe learning from mistakes is far better than not allowing yourself to make the mistake. It's not even so much people that do that as people that do it then bleat about it when the question is wrong that get me, and there were more than a handful going back through this thread admitting as much

    'I ran the code and it said 1,1 so i chose that and it gave me the wrong answer and i'm not happy!'

    Just doesn't seem right to me...

Viewing 15 posts - 106 through 120 (of 132 total)

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