重回故里 Java

不积跬步,无以至千里;不积小流,无以成江海
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

sql server统计数据库中所有表的记录条数

Posted on 2009-06-25 17:22  .net 新生活 新旅程  阅读(970)  评论(0编辑  收藏  举报

set nocount on
if object_id(N'tempdb.db.#temp') is not null
  drop table #temp
create table #temp (name sysname,count numeric(18))

insert into #temp
select o.name,i.rows
from sysobjects o,sysindexes i
where o.id=i.id and o.Xtype='U' and i.indid<2

select count(count) 总表数,sum(count) 总记录数 from #temp
select * from #temp
set nocount off

 

 

该方法执行速度快,但是结果好象并不是太准确,稍微有一些偏差.方法主要是利用了系统索引表sysindexes中索引ID indid<1的行中的rows列存有该表的行数这一特点.