What is the difference between following SQL Server 2008 statements?
SELECT COUNT(*) FROM dbo.Regular_Report
SELECT COUNT(0) FROM dbo.Regular_Report
SELECT COUNT(1) FROM dbo.Regular_Report
SELECT COUNT(100) FROM dbo.Regular_Report
SELECT COUNT(ID) FROM dbo.Regular_Report
The first four are all identical - they count the total number of rows.
The last one counts the number of rows where ID is not null.
count(id) will count the non-null values in the id field.
All the other will count the number of records.
(The ones with literal numbers instead of * will count all the records where that value is not null. Probably the query planner will recognise that the literal value will never be null for any record, and do the same as count(*) instead of actually counting the non-null values.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With