Solved

SQL 2005 - table row count

Posted on 2012-03-30
1
501 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:
ScottPletcher 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need help with a query 7 60
sql calculate reminders 11 56
PERFORMANCE OF SQL QUERY 13 58
SQL query to summarize items per month 5 28
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now