65.9K
CodeProject is changing. Read more.
Home

Record Count of Tables in SQL Server

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Aug 16, 2011

CPOL
viewsIcon

7452

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.

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.