Tuesday, June 1, 2010

Dont use count(*) -- Not good practice

“Select Count (*) From table”.
The problem with this instruction is that most of the times it performs a Table or Index Scan to return the amount of records in the table. For large tables this is a synonymous of slow query and high consumption of server resources.

Use the following query to find out rows in a table.

SELECT rows FROM sysindexes
WHERE id = OBJECT_ID('table_name') AND indid<2

No comments: