INF: Fast Query to Return Number of Rows in a TableLast reviewed: April 25, 1997Article ID: Q73006 |
The information in this article applies to:
- Microsoft SQL Server version 4.2 for OS/2
SUMMARYThe following is the query most often used to return the number of rows in a given table:
SELECT COUNT(*) FROM <table name>For large tables, this query may take a while to run. There is, however, a faster method of determining the number of rows in a table.
MORE INFORMATIONIn some applications, you might want to maintain a constant tally of the number of rows in a table. If you use the query shown above, the query expends considerable overhead counting each row of the table. The "rows" column in the sysindexes table can also return the current number of rows in any given table. Use the following query to retrieve the row count comparatively quickly, since querying the sysindexes table needs to find only one row:
SELECT rows FROM sysindexes WHERE id = object_id ("<table name>") AND indid < 2 Notes
|
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |