The Last Day Of Summer

.NET技术 C# ASP.net ActiveReport SICP 代码生成 报表应用 RDLC
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

获取当前数据库中所有表的记录数

Posted on 2004-07-19 15:09  Cure  阅读(2012)  评论(3编辑  收藏  举报

获取当前数据库中所有表的记录数:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetRecordCountsForAllTables]'and OBJECTPROPERTY(id, N'IsProcedure'= 1)
drop procedure [dbo].[GetRecordCountsForAllTables]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE  Procedure dbo.GetRecordCountsForAllTables AS

select  'Owner'=convert(char(10),t.TABLE_SCHEMA),
      
'Table Name'=convert(char(25),t.TABLE_NAME),
      
'Record Count'=max(i.rows)
from sysindexes i, INFORMATION_SCHEMA.TABLES t
where t.TABLE_NAME = object_name(i.id)
      
and t.TABLE_TYPE = 'BASE TABLE'
group by t.TABLE_SCHEMA, t.TABLE_NAME
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO