Tuesday, February 14, 2012

counting all records in a database

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

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

groupby

object_name([object_id])

-- 2000

dbcc updateusage('northwind')

go

select

object_name([id]),

rowcnt

from

dbo.sysindexes

where

indid in(0, 1)

andobjectproperty([id],'IsUserTable')= 1

AMB

|||

This is pretty easy:

EXECsp_msforeachtable'sp_spaceused "?"'

No comments:

Post a Comment