• gkganeshbe (12/26/2012)


    Is there any performance difference in the below given three queries.

    Note: Col1 is NOT NULL column

    SELECT COUNT(*) FROM Sales.SalesOrderDetail;

    SELECT COUNT(Col1) FROM Sales.SalesOrderDetail;

    SELECT COUNT(0) FROM Sales.SalesOrderDetail;

    Not really. The second one with COUNT(Col1) may take a very small performance hit during the parse and bind phases, to check whether there is a Col1 column and if it's nullable, but that is an extremely short amount of time.


    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/