I want to know just for curiosity that, does Select Count(*) from SomeTableName
also traverses all the rows of the database as that of Select * from SomeT
SELECT Count(*)
FROM SomeTableName
will always count all rows. Though (unlike SELECT *
) it does not have to read all columns and can use the narrowest (non filtered) index available to do so.
Unlike MySQL (MyISAM engine) it does not retrieve the value from metadata.
A rowcount value is available in the metadata and can be retrieved from sys.partitions but this is never used for COUNT
queries and isn't always accurate.