Way to count total record in a table or in Dynamic Query

You can use COUNT function in SQL SERVER to count total number of record in a table.

  • COUNT(*)
  • COUNT(Field with Primary Key)
  • COUNT(1)
Among three of these i suggest you to use last two.When you are using temporary table or table variable, you can use @@ROWCOUNT, which represents total number of row affected while insert data on table.So it is the total number of record that table has.Refer to SQL OPTIMIZATION TIPS AND TRICK for more optimization tricks.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form