Counting rows for all tables at once

前端 未结 6 1983
梦毁少年i
梦毁少年i 2020-12-09 10:28

I\'m using SQL Server 2005 and would like to know how I can get a list of all tables with the number of records in each.

I know I can get a list of tables using the

6条回答
  •  死守一世寂寞
    2020-12-09 11:08

    This is my method:

    create table #rowcount (tablename varchar(128), rowcnt int)
    exec sp_MSforeachtable 
       'insert into #rowcount select ''?'', count(*) from ?'
    select * from #rowcount
        order by tablename
    drop table #rowcount
    

    works like a charm

提交回复
热议问题