Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401

    Unanswered: Table Rowcounts for a database

    Hi guys .. quick question

    Does anybody here have a query handy to get the counts of rows in tables in a database.

    I know it can be done by using systables but right now I am in too confused a state to write the query by figuring out the right columns and tables

    Thanks in advance
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    SELECT o.name, i.rowcnt
       FROM dbo.sysobjects AS o
       JOIN dbo.sysindexes AS i
          ON (i.id = o.id)
       WHERE  i.indid IN (0, 1)
    I would recommend that you run
    Code:
    EXECUTE sp_MSForEachTable 'UPDATE STATISTICS ?'
    ...before using that query though.

    -PatP

  3. #3
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    sp_MSforeachtable "select '?', count(*) from ?"

    -- This is all just a Figment of my Imagination --

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Tom has a great suggestion for small databases. I know that Enigma doesn't deal with small databases though, so I had some additional insight into what Enigma wanted and why he wanted it that wasn't explicitly posted in the original question.

    -PatP

  5. #5
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Thanks a lot guys ... you made my work a lot easier
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •