Count(*) vs Count(Id) in sql server 2005

前端 未结 2 477
心在旅途
心在旅途 2021-02-07 04:25

I use SQL COUNT function to get the total number or rows from a table. Is there any difference between the two following statements?

SELECT COUNT(*)         


        
2条回答
  •  渐次进展
    2021-02-07 04:52

    count(id) needs to null-check the column (which may be optimized away for a primary key or otherwise not-null column), so count(*) or count(1) should be prefered (unless you really want to know the number of rows with a non-null value for id).

提交回复
热议问题