September 13, 2012 at 3:39 pm
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)
September 13, 2012 at 4:46 pm
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 🙂
September 13, 2012 at 4:58 pm
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
September 13, 2012 at 5:33 pm
i dont hv millions of rows ,for simple rows like 100,its time i s 0
September 13, 2012 at 6:40 pm
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
September 14, 2012 at 6:36 am
ok.
select count(*) taking 0 seconds,and select * from taking 0.08
but why?i dont know that
September 14, 2012 at 6:44 am
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
September 14, 2012 at 7:51 am
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?
September 14, 2012 at 9:46 am
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
September 14, 2012 at 9:59 am
No you can't
September 14, 2012 at 10:00 am
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.
September 14, 2012 at 10:28 am
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
September 14, 2012 at 10:31 am
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
September 14, 2012 at 10:44 am
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.
September 14, 2012 at 5:54 pm
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