September 30, 2014 at 2:22 am
I got it "right" by eliminating 0 and 20, but the answer is incorrect! When I tested the query, I got 5 values in master and I got different numbers for each database.
/Hรฅkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
September 30, 2014 at 2:24 am
Eirikur Eiriksson (9/30/2014)
Thank you for the question Amit.Given options of 0,2 and 20 with the set's cardinality of 20 makes this kind of obvious; the granularity of syscolumns is {object,column}, one can rule out 0 as the query will return values, one can also rule out twenty as most objects have more than one column which leaves 2 as the only applicable answer.
๐
2 is not a correct answer as it will depend on the database. I also eliminated 0 and 20 to get my points, but the answer is still wrong.
/Hรฅkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
September 30, 2014 at 2:36 am
Same for me - the result is database-dependent, so no answer is correct. Are the questions verified before posting ๐ ?
September 30, 2014 at 3:57 am
This was removed by the editor as SPAM
September 30, 2014 at 4:37 am
At least following the recent spate of RAND() questions I found it quicker to spot that the question had gone wrong. I'm beginning to feel I finally know RAND.
September 30, 2014 at 4:48 am
The mistake in the question was overlooking the fact that sys.syscolumns will have different contents in different databases.
But more than that, you couldn't guarantee the statement would return the same results in the same database: without an ORDER BY clause in the SELECT statement the TOP 20 clause could return any 20 rows.
September 30, 2014 at 4:51 am
hakan.winther (9/30/2014)
Eirikur Eiriksson (9/30/2014)
Thank you for the question Amit.Given options of 0,2 and 20 with the set's cardinality of 20 makes this kind of obvious; the granularity of syscolumns is {object,column}, one can rule out 0 as the query will return values, one can also rule out twenty as most objects have more than one column which leaves 2 as the only applicable answer.
๐
2 is not a correct answer as it will depend on the database. I also eliminated 0 and 20 to get my points, but the answer is still wrong.
Knowing that id is not the primary key column of syscolumns and no specific database was designated for the execution of the code, the answer 2 (two) is the only reasonable answer.
๐
September 30, 2014 at 5:30 am
Stewart "Arturius" Campbell (9/30/2014)
The answer, however, should have been "It depends"
+1 to that. I find the interesting part is that a function that's supposed to return "random numbers" returns the same numbers for one of the posters as the ones I got on my system. On the surface, it appears wrong, but if the same seeds are used, it returns the same quantities of the same numbers. It really is nothing more than a function that's consistent, but not always.
I don't mean to spark a mathematical debate here, but what is truly random anyway? ๐
September 30, 2014 at 5:36 am
I executed on SQL 2008, SQL 2008R2 and SQL 2012 - I got 6 different random numbers in all 3 test environments. I then started running the query against different databases and received 2 different numbers. Not a good question.
September 30, 2014 at 5:45 am
Agree with many posts here. Interesting idea, but not correct implementation of the question and options.
This is my result (SQL 2012, master database) 6 DIFFERENT results:
(No column name)
0.713591993212924
0.713591993212924
0.713591993212924
0.713647892126698
0.713647892126698
0.713647892126698
0.713647892126698
0.713722424011731
0.713722424011731
0.713722424011731
0.713722424011731
0.713722424011731
0.713722424011731
0.713722424011731
0.713852854810538
0.713871487781797
0.713871487781797
0.713908753724313
0.713908753724313
0.713908753724313
I believe that the question should be corrected.
September 30, 2014 at 6:01 am
I also got 3, 5 or 6 distinct values depending on the database.
September 30, 2014 at 6:09 am
I got it right but it's true that you can't really know how many different distinct values you will generate unless you know for certain the values that the Rank function will return.
Definitely the question and answers could have been better presented.
Regardless, I thank the author and encourage him to keep posting questions.
---------------
Mel. ๐
September 30, 2014 at 6:10 am
andrew.ing (9/30/2014)
The mistake in the question was overlooking the fact that sys.syscolumns will have different contents in different databases.But more than that, you couldn't guarantee the statement would return the same results in the same database: without an ORDER BY clause in the SELECT statement the TOP 20 clause could return any 20 rows.
The ORDER BY as part of the OVER clause guarantees you that.
---------------
Mel. ๐
September 30, 2014 at 6:23 am
We have all been drilled that without an order by there is no guarantee of the order of the records. That being said any number from 1 to 20 could conceivably come up.
ToddR
September 30, 2014 at 6:35 am
This was removed by the editor as SPAM
Viewing 15 posts - 16 through 30 (of 60 total)
You must be logged in to reply to this topic. Login to reply