| Login

Search this Blog


Links I like to keep around




Here are the most recent postings to this blog. Use the archive calendar or search to find other entries.
Jul3

Written by:R Teachout
7/3/2008 1:50 AM

Just a quick way to find the number of rows in all of your tables.

use [dbname]
go
set nocount on
declare @cnt int
declare @table varchar(128)
declare @cmd varchar(500)
create table #rowcount (tablename varchar(128), rowcnt int)
declare tables cursor for
           select table_name from information_schema.tables
           where table_type = 'base table'
open tables
fetch next from tables into @table
while @@fetch_status = 0
begin
        set @cmd = 'select ''' + @table + ''', count(*) from ' + @table
        insert into #rowcount exec (@cmd)
        fetch next from tables into @table
end
CLOSE tables
DEALLOCATE tables
select * from #rowcount
    order by tablename
drop table #rowcount

Tags:

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel  

I do not fear computers. I fear the lack of them.
-Isaac Asimov

Inspired by Nina