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

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

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

原文地址:https://www.cnblogs.com/dahuzizyd/p/25565.html