tags:

views:

64

answers:

2

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 all tables in a given database.

+3  A: 
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.

Remus Rusanu
You are of course correct. Thank you very much :-)
ptrn
+2  A: 

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;
Daniel Vassallo
This is also very useful for me. Thanks :-)
ptrn