/****** Object: Stored Procedure dbo.sp_rowcount Script Date: 7/28/1999 3:15:53 PM ******/ if exists (select * from sysobjects where id = object_id('dbo.sp_rowcount') and sysstat & 0xf = 4) drop procedure dbo.sp_rowcount GO create procedure sp_rowcount @tablename varchar(32) = null as /************************************************************************************************** author: douglas a. bass date: 07/29/1999 description: returns rowcounts for all tables in the current database, or if @tablename is provided, for that table only. caveat: this procedure makes use of sysindexes, so make sure all indexes are up-to-date thanks to: jon a. kale **************************************************************************************************/ declare @dbname varchar(32) set nocount on if @tablename is not null begin if exists (select * from sysobjects where id = object_id(@tablename) and sysstat & 0xf = 3) begin select o.name, i.rows from sysobjects o inner join sysindexes i on (o.id = i.id) where o.id = object_id(@tablename) and i.indid < 2 order by o.name end else begin select @dbname = db_name() raiserror ('Object "%s" does not exist in database "%s" or is not a user table.', 16, 1, @tablename, @dbname) end end else begin select o.name, i.rows from sysobjects o inner join sysindexes i on (o.id = i.id) where o.type = 'u' and i.indid < 2 order by o.name end -- GO