SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 How many rows per table?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jezemine
Flowing Fount of Yak Knowledge

USA
2886 Posts

Posted - 02/25/2008 :  17:04:44  Show Profile  Visit jezemine's Homepage  Reply with Quote
Here's a little script to tell you how many rows you have per table in a 2005 database.

Nothing fancy, but I found it useful.


declare @t table (partition_number int not null, name sysname not null, rows bigint not null)

insert @t
select 
    i.partition_number
    ,o.name
    ,i.rows
from sys.partitions i
join sys.objects o on i.object_id=o.object_id
where o.type='U' and index_id IN (0, 1)

select * from 
(
    select null as partition_number, 'TOTAL' as name, sum(rows) as rows from @t
    union all 
    select * from @t
) a 
order by 1, 3 desc



elsasoft.org

Edited by - jezemine on 02/26/2008 12:18:28

jezemine
Flowing Fount of Yak Knowledge

USA
2886 Posts

Posted - 02/25/2008 :  19:15:27  Show Profile  Visit jezemine's Homepage  Reply with Quote
incidentally, total rows in one of the dbs i am working on at the moment: 6424622745

big!


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 02/26/2008 :  01:38:49  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Note that You need to run

DBCC UPDATEUSAGE ('database_name') WITH COUNT_ROWS

for accurate row count

Madhivanan

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

Arnold Fribble
Yak-finder General

United Kingdom
1961 Posts

Posted - 02/26/2008 :  09:47:41  Show Profile  Reply with Quote
You know you are counting the rows in all the user tables' indexes? (though not any rows in indexes on views)

If you only want to count heaps and clustered index sizes, you'd need to filter on index_id IN (0, 1)
Go to Top of Page

jezemine
Flowing Fount of Yak Knowledge

USA
2886 Posts

Posted - 02/26/2008 :  12:27:31  Show Profile  Visit jezemine's Homepage  Reply with Quote
thanks, fixed. now my count is only 6408980460


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 02/27/2008 :  01:42:03  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Some other approaches I suggested
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000