Solved

SQL 2005 - table row count

Posted on 2012-03-30
1
511 Views
Last Modified: 2012-06-27
I would like to alter this query so it includes a row count for each table.

SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;

thank you
0
Comment
Question by:dastaub
1 Comment
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 37788961
SELECT SCHEMA_NAME(t.schema_id) AS SchemaName, t.name AS TableName, dps.row_count
FROM sys.tables t
INNER JOIN sys.dm_db_partition_stats dps ON
    dps.object_id = t.object_id AND
    dps.index_id IN (0, 1)
WHERE OBJECTPROPERTY(t.object_id,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question