simple que

  • hi,

    i have 1 table which has millions of rows, i am doing select * from tablename

    and select count(*) from tablename

    does this both take same time or different,if different then why,if same then why.

    (2) If i define variable global variable in my stored proc doesnt it appear inside another stored proc.(nested)

  • harri.reddy (9/13/2012)


    hi,

    i have 1 table which has millions of rows, i am doing select * from tablename

    and select count(*) from tablename

    does this both take same time or different,if different then why,if same then why.

    (2) If i define variable global variable in my stored proc doesnt it appear inside another stored proc.(nested)

    Looks like interview questions to me.

    What are your answers so far?

    #2 looks a bit irrelevant to SQL Server 🙂

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • harri.reddy (9/13/2012)


    (2) If i define variable global variable in my stored proc doesnt it appear inside another stored proc.(nested)

    Perhaps because SQL doesn't have global variables?

    For the first, why don't you create such a table, run both queries and see which, if either, is faster?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • i dont hv millions of rows ,for simple rows like 100,its time i s 0

  • create one!

    try this one:

    select top 1000000 1 as a

    into #t

    from sys.columns c1

    cross join sys.columns c2

    cross join sys.columns c3

    cross join sys.columns c4

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • ok.

    select count(*) taking 0 seconds,and select * from taking 0.08

    but why?i dont know that

  • Have a look at the execution plan.

    Also consider, how much data has to be transmitted and displayed in each case?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Literally speaking,

    a) "Select *" will return the result set , whereas "Count(*)/Count(1)" will return a scalar value and this will result in significance difference in terms of I/O

    b) Other fact is, there is no hard & fast rule to judge the performance; everything depends on the many factors like indexes used, statistics update, etc.....

    For your other question, you can pass the variable as a parameter. Do you have any concerns by doing so with respect to your scenario?

  • thanks for your response,

    for my other question,

    it was something ,if i define global variable in sp,will it can be access in inside stored procedure

  • No you can't

  • harri.reddy (9/14/2012)


    thanks for your response,

    for my other question,

    it was something ,if i define global variable in sp,will it can be access in inside stored procedure

    Could you please advise how did you managed to define a global variable in sp?

    Is it some kind of hidden SQL Server feature?

    Thanks.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • harri.reddy (9/14/2012)


    it was something ,if i define global variable in sp,will it can be access in inside stored procedure

    As I mentioned above, SQL Server doesn't have global variables.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • bala.a (9/14/2012)


    Literally speaking,

    a) "Select *" will return the result set , whereas "Count(*)/Count(1)" will return a scalar value and this will result in significance difference in terms of I/O

    IO, maybe, maybe not. Depends on whether there are indexes available.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Eugene Elutin (9/14/2012)


    harri.reddy (9/14/2012)


    thanks for your response,

    for my other question,

    it was something ,if i define global variable in sp,will it can be access in inside stored procedure

    Could you please advise how did you managed to define a global variable in sp?

    Is it some kind of hidden SQL Server feature?

    Thanks.

    Yes, is a hidden, undocumented feature that can be only used by a few members of a secret society. Gail might know but she won't tell us as her rights would be dismissed.

    To note: that was a joke.

    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
  • do you mean global ##temptables

    These persist between stored procedures until the session is ended or the connection is dropped.

    you can fill a ##temptable in one procedure and access the data in another, but it is generally not good practice.

Viewing 15 posts - 1 through 15 (of 20 total)

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