Home / SQL Server / Script to count nr of rows in all tables

Script to count nr of rows in all tables

This script can be used as a view to count the number of rows in all SQL tables in your database. This can be very usefull.

CREATE VIEW [dbo].[vwTableListRowCount]
AS
-- EXAMLE
-- SELECT * FROM vwTableListRowCount ORDER BY TableName
SELECT TOP 100 PERCENT O.name AS TableName,
    s.name AS SchemaName,
    I.rowcnt AS NrOfRecords
FROM sysobjects AS O
    INNER JOIN sysindexes AS I ON O.id = I.id
    INNER JOIN sys.schemas AS S ON O.uid = S.schema_id
WHERE  I.indid IN (0, 1)
    AND O.xtype = 'u'
    AND O.[name] NOT IN ('sysdiagrams', 'dtproperties')
ORDER BY O.[name]

 

Check Also

Nederlandse postcodetabel

Postcodetabel van Nederlands + SQL Script

Inleiding De Nederlandse Postcodetabel bevat informatie over alle postcodes die in Nederland bekend zijn. Dit …

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *