-- This Script provides a count for all T tables in the current database -- Updated 11/8/12 DR added the 'resolvedschemaId' qual to the arschema query in the cursor -- Use At your own risk, and please, have a current backup of your system -- This must be run on the ARSystem database. SET NOCOUNT ON SET ANSI_WARNINGS OFF -- declaration of all variables needed for processing declare @schemaid int, @SQLStatement nvarchar (1000), @tablename varchar (80), @schemaname varchar (80) -- schema_cursor cycles through the schemaids in the arschema table declare schema_cursor cursor for select schemaid from arschema where schematype<=2 and schemaId=resolvedschemaId order by 1 IF exists (select * from dbo.sysobjects where name = 'ARTableCount' and type = 'U') drop table ARTableCount create table ARTableCount (schemaid varchar (5) not null, schemaname varchar (80), rowcounter int) open schema_cursor fetch next from schema_cursor into @schemaid WHILE @@FETCH_STATUS = 0 begin select @schemaname=name from arschema where schemaId=@schemaId select @SQLStatement=N'insert into ARTableCount select '+ cast(@schemaid as nchar)+', ' +char(39) + @schemaname + char(39) +', count(*) from T' + rtrim(CONVERT(char(5), @schemaid)) exec sp_executesql @SQLStatement fetch next from schema_cursor into @schemaid end close schema_cursor deallocate schema_cursor select * from ARTableCount order by rowcounter desc -- End Script ---