• Oleg Netchaev (11/9/2010)


    Hugo Kornelis (11/9/2010)


    Oleg Netchaev (11/8/2010)


    should be count(*) or even better count(1)

    Why would that be better?

    Simply due to sanity reasons.

    (...)

    While this is true that in newer versions of Oracle count('X') is no longer special, and in SQL Server it does not make any difference whether count(*) or count(1) is used, many people like me still opt to avoid count(*) at all costs, just for sanity check if anything.

    Hi Oleg,

    I assumed that was the case. The reason I always prefer to use SELECT * in a COUNT (unless I relaly need to know the number of non-NULL values in a column) is that this clearly documents, a lot better than any other option, that I am counting ROWS, not VALUES.

    And there is indeed no performance difference. THis might have been true in the dark ages, and on Oracle, but definitely not on current SQL Server versions.


    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/