October 1, 2012 at 1:37 pm
Hello All,Thank you all for such a nice platform to discuss issue pertaining to SQL.I have a situation where I need to read 20 tables one by one and based on last update we have to produce total record count inside the table.One way i am doing select query on each table and get the record count based on last updated date.In that way i have to do multiple select on tables and get the record count.Jus thought to share question in forum to get any alternate way to read the tables.
Table Name RecordCount (based on last update date)
A 200
B 230
C 238
D 250
Appreciate your help.
Thanks
R
October 1, 2012 at 2:10 pm
the row counts are already materialized in one of the system tables, so if you query that, it will be boatloads faster than querying each table individually:
Select
OBJECT_NAME(object_id) as TableName,
SUM(rows) as NumRows,index_id
From sys.partitions p
Inner Join sys.sysobjects o
on p.object_id = o.id
Where index_id in (0,1) --either PK index or the HEAP index
And o.type = 'U'
Group By object_id,index_id
Order By NumRows Desc
Lowell
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply