Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Table names and record counts

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-26 : 08:18:12
Matt writes "How can I create a query that lists all the names of the tables in a database and the number of records in each?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-01-26 : 08:20:53
There's a shortcut you can use in SQL Server:

SELECT Object_name(id) AS tbl, rows FROM sysindexes WHERE id>100 AND indid<2 ORDER BY tbl

Two things:

1. Row counts in sysindexes can be incorrect, you should run DBCC UPDATEUSAGE periodically to make sure they're up-to-date.
2. This query may not work in future releases of SQL Server. There will be significant changes to system tables in SQL2005.
Go to Top of Page
   

- Advertisement -