Gess Man


Is there an easy way to count all records in a database


Re: counting all records in a database

hunchback


Gess Man,

I fair one could be using sys.dm_db_partition_stats, if you are using SQL Server 2005. For 2000, use sysindexes, but execute "dbcc updateusage" before executing the "select" statement.

-- 2005

select

object_name([object_id]),

sum(row_count) as row_cnt

from

sys.dm_db_partition_stats

where

objectproperty([object_id], 'IsUserTable') = 1

group by

object_name([object_id])

-- 2000

dbcc updateusage('northwind')

go

select

object_name([id]),

rowcnt

from

dbo.sysindexes

where

indid in (0, 1)

and objectproperty([id], 'IsUserTable') = 1

AMB






Re: counting all records in a database

GlennAlanBerry

This is pretty easy:

EXEC sp_msforeachtable 'sp_spaceused " "'