Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Empty Tables

Author  Topic 

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-04-16 : 07:18:00
I was wondering if there is a way of finding out which tables in a databases hold zero rows of data.

That is other that running the

SELECT Count(*) From [Table Name]

Statement, I've though of happen a cursor to run through the tables but don't reall like that solution.

Any ideas Guys

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-04-16 : 07:43:33
select distinct
sys.tables.name,sys.partitions.rows
from sys.partitions inner join sys.tables
on sys.partitions.object_id = sys.tables.object_id
WHERE rows = 0
ORDER BY SYS.partitions.rows desc
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-04-16 : 08:22:25
Thanks for that excellent help
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-04-16 : 08:31:30
welcom!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-16 : 08:39:42
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/02/different-ways-to-count-rows-from-a-table.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -