Count number of entries in whole SQL Server database
Is there any way I can count the number of all entries in a SQL Server database? Preferably with only one query.
Edit: The total amount of entries in a开发者_StackOverflowll tables in a given database.
select sum(rows) from sys.partitions;
This is a correct answer, for a conveniently definition of 'entry' (chosen by me): a row in a heap or a b-tree.
This query will return a list of all the tables, with an approximate row count for each table:
SELECT
[TableName] = sysobjects.name,
[RowCount] = MAX(sysindexes.rows)
FROM
sysobjects,
sysindexes
WHERE
(sysobjects.xtype = 'U') AND (sysindexes.id = OBJECT_ID(sysobjects.name))
GROUP BY
sysobjects.name
ORDER BY
2 DESC;
精彩评论