Welcome
Login  |  Register
Tuesday, January 06, 2009
  Search
You are here:Knowledge Base
 
 
 

 Please Register or login to view our private forums, it is free!!

Subject: display # of rows in tables in a db
Prev Next
You are not authorized to post a reply.

Author Messages
cmuenchUser is Offline
Posts:59

05/31/2007 11:00 AM  
The following script will show you the number of rows in all the tables in your database.
[sql]
USE DatabaseName
GO
CREATE TABLE #temp (
table_name sysname ,
row_count int,
reserved_size varchar(50),
data_size varchar(50),
index_size varchar(50),
unused_size varchar(50))
SET NOCOUNT ON
INSERT #temp
EXEC sp_msforeachtable 'sp_spaceused ''?'''
SELECT a.table_name,
a.row_count,
count(*) as col_count,
a.data_size
FROM #temp a
INNER JOIN information_schema.columns b
ON a.table_name collate database_default
= b.table_name collate database_default
GROUP BY a.table_name, a.row_count, a.data_size
ORDER BY CAST(Replace(a.data_size, ' KB', '') as integer) desc
DROP TABLE #temp

[/sql]
You are not authorized to post a reply.
Forums > Knowledge Base Systems > MSSQL > display # of rows in tables in a db



ActiveForums 3.7
 
Copyright 2006-7 Vigilant Support