Why you need to know
There are lots of reasons why you might want to know the number of records in your tables. Database maintenance is one; user and business interest is another – I have been asked how many records are in certain tables for sales calls, blog posts, invoicing and many other reasons.
How do you count the number of records?
If you only want to know the number of records in a single table, you just run this command: –
SELECT COUNT(1) FROM [Table]
If you want to know the number of records in all tables, you can run this: –
SELECT
sysobjects.Name
, sysindexes.Rows
FROM
sysobjects
INNER JOIN sysindexes
ON sysobjects.id = sysindexes.id
WHERE
type = 'U'
AND sysindexes.IndId < 2
ORDER BY
sysindexes.[Rows] Desc