select no. of rows from the current database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ssingh

    select no. of rows from the current database

    Hello,
    I want to select the names and number of rows of all tables in the
    current database, whose name starts with 'sys'
    my query is:

    select o.[name], sum(i.[rows]) as numbers
    from sysobjects o
    inner join sysindexes i
    on (o.[id] = i.[id])
    where o.[name] like 'sys%'and i.indid=1
    group by o.[name]


    the result of the query is (depending of the database) :


    name numbers
    sysaltfiles 14
    syscharsets 114
    syscolumns 4934
    syscomments 2035
    sysconfigures 38
    sysdatabases 7
    sysdepends 5524
    sysdevices 6
    sysfilegroups 1
    sysfulltextcata logs 0
    sysfulltextnoti fy 0
    sysindexes 98
    syslanguages 33
    sysmessages 3795
    sysobjects 1285
    syspermissions 806
    sysproperties 0
    sysreferences 0
    sysservers 1
    systypes 26
    sysusers 14
    sysxlogins 3


    But when I count the number of rows of "sysobjects ", I get
    numbers=1298, which is different from the result displayed above and
    same goes for "syscolumns ".
    I also tried "dbcc updateusage [0]" to update the SQL Server but I
    didnt help me.
    Can anyone please advice me on this behaviour?

  • Erland Sommarskog

    #2
    Re: select no. of rows from the current database

    ssingh (singh.181@gmai l.com) writes:
    I want to select the names and number of rows of all tables in the
    current database, whose name starts with 'sys'
    my query is:
    >...
    But when I count the number of rows of "sysobjects ", I get
    numbers=1298, which is different from the result displayed above and
    same goes for "syscolumns ".
    I also tried "dbcc updateusage [0]" to update the SQL Server but I
    didnt help me.
    Can anyone please advice me on this behaviour?
    Add WITH COUNT_ROWS to DBCC UPDATEUSAGE.

    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • ssingh

      #3
      Re: select no. of rows from the current database

      Thank you Erland. It worked for me.
      Erland Sommarskog wrote:
      ssingh (singh.181@gmai l.com) writes:
      I want to select the names and number of rows of all tables in the
      current database, whose name starts with 'sys'
      my query is:
      ...
      But when I count the number of rows of "sysobjects ", I get
      numbers=1298, which is different from the result displayed above and
      same goes for "syscolumns ".
      I also tried "dbcc updateusage [0]" to update the SQL Server but I
      didnt help me.
      Can anyone please advice me on this behaviour?
      >
      Add WITH COUNT_ROWS to DBCC UPDATEUSAGE.
      >
      --
      Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se
      >
      Books Online for SQL Server 2005 at

      Books Online for SQL Server 2000 at
      http://www.microsoft.com/sql/prodinf...ons/books.mspx

      Comment

      Working...