Read n-table from SQL Database

  • 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

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply