Monday, December 04, 2006

Query: number of rows SQL Server

There is a fast and easy way to determine the number of rows in a table. Instead of using queries like:
  Select COUNT(*) from tablename
where it is necessary to use the datatable, you can use the systemtable:
  SELECT rows
  FROM sys.sysindexes
  WHERE (id = OBJECT_ID('tablename'))
  AND (name = 'PrimaryKey name')
.
This is very fast, because you select only one row.

No comments: