Count(1) vs Count(*) in T-SQL? RRS feed

  • Question

  • Hi,I have a long-standing doubt about the performance of the count statement. I was told by developers in PL/SQL that using count(1) to find the rowcount was much more high-performing than using count(*), as count(*) fetches all the rows into memory before getting the exact count. I want to know whether this holds true for T-SQL as well, or are the two just the same? Thanking  in anticipation of reply :) .
    Sunday, February 18, 2007 7:23 PM


  • This is actually a failing of PL/SQL. T-SQL recognises that you're talking about count(*) and will consider any row. The same occurs with WHERE EXISTS (SELECT *...

    So, in T-SQL use count(*) and let the optimiser do its stuff. In PL/SQL, acknowledge that it's not as good (hehe), and use count(1).

    Sunday, February 18, 2007 10:21 PM