Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database

Record Count of Tables in SQL Server

5.00/5 (1 vote)
16 Aug 2011CPOL 7.5K  
Sometimes it is necessary to have the schema name included as well. I concatenate with the table name for my convenience, but it is not vital to do so.SELECT sys.sysindexes.rows, sys.schemas.name + '.' + sys.objects.nameFROM sys.objectsINNER JOIN sys.schemasON ...

Sometimes it is necessary to have the schema name included as well. I concatenate with the table name for my convenience, but it is not vital to do so.


SQL
SELECT        sys.sysindexes.rows, sys.schemas.name + '.' + sys.objects.name
FROM          sys.objects
INNER JOIN    sys.schemas
ON            sys.objects.schema_id = sys.schemas.schema_id
INNER JOIN    sys.sysindexes
ON            sys.objects.object_id = sys.sysindexes.id
WHERE         sys.objects.type = 'u'
AND           sys.objects.name <> 'dtproperties'
AND           sys.objects.name <> 'sysdiagrams'
AND           sys.sysindexes.indid < 2

Also get rid of a couple of tables which we don't need to see in the count.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)