Difference between count (1) and count (*)

Difference between count (1) and count (*)

What is the difference between count(1) and count(*) ?

There is no difference between count (1) and count (*). The best way to prove it compares the execution plan for listed query.

Select Count (1) From [Table_Name]
Select Count (*) From [Table_Name]

 

Both the query have same execution plan. In both the above query following things happens

  1. First it scans (index scan or table scan is depends on indexes of the table) rows from the database table.
  2. Then it computes the count.
  3. After that it compute the new value from existing values.
  4. In last query display the output.

This shows that the both query execute in same manner. Both perform same task uses same amount of memory and must execute in same amount of time.

0 Comments
Leave A Comment

Please login to post your valuable comments.

Join the newsletter

Get the latest vLemonn news first

share