• I was so caught up in responding to (and feeling bad about) the mistakes, that I forgot to thanks everyone for the kind words. All respondents to far have indicated that they like this (type of) question. Thanks! 😉

    Dave Brooking (11/16/2011)


    The explanation is also well constructed, however I think it also contains a couple of typos where the 200,000 pages becomes 20,000 part way through.

    They just keep coming, don't they?

    You are right, all the 20,000's should be 200,000's. The numbers derived from them are correct, though - I made the mistake while typing the explanation, but not while doing the math.

    Jan Van der Eecken (11/16/2011)


    Hugo, there is another issue. DemoTableKey is the PRIMARY KEY of that table, so it must be unique. But what does one put in there (you are not specifying that) ;-).

    Ah, but this was deliberate! I deliberately did NOT create an integer primary key, again in an attempt to make it a bit harder for those who might be tempted to simply "run the code". I hope the question made it clear that there were no values (although with hindsight, I could have added "and with unique values for the DemoTableKey column" to the text). Since char(10) allows for a theoretical maximum of 255 ^ 10 = 1162523670191533212890625 values, this is definitely not impossible. At only a million rows in the table, you could even create a string of 10 randomly chosen characters and have less than 0.00001% chance of getting a duplicate key violation.


    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/