Results 1 to 5 of 5

Thread: count all rows

  1. #1
    Join Date
    Nov 2002
    Posts
    3

    Unanswered: count all rows

    is there a utilitie which counts all rows in all database-tables?

    Joachim from Germany

    Sybase SQL-Anywhere Version 5.5

  2. #2
    Join Date
    Jan 2003
    Posts
    55
    you can just use the query :

    select count(*) from table_name

    and it will return u the num of rows for that particular table..
    hopefully this is what u were looking for and it helps

    -shuchi
    You try and try again..but then give up, there's no sense in being a complete fool about it!!!

  3. #3
    Join Date
    Jan 2003
    Posts
    26

    Re: count all rows

    I think you can just use this:
    sp_spaceused table_name

    The second field returned is the row total. It'll be much faster than doing the actual count on a big table.

  4. #4
    Join Date
    Jan 2003
    Posts
    55
    hmm...
    yah this will also work fine but just that if the table concerned is a view then this function doesnt work as there is no space reseved for views.

    maybe for a view you can use the conventional select count(*) otherwise this one line query is perfect

    -shuchi
    You try and try again..but then give up, there's no sense in being a complete fool about it!!!

  5. #5
    Join Date
    Aug 2002
    Location
    Madrid, Spain
    Posts
    97

    Re: count all rows

    Originally posted by frankp
    I think you can just use this:
    sp_spaceused table_name

    The second field returned is the row total. It'll be much faster than doing the actual count on a big table.
    A necessary warning is to remind that sp_spaceused
    information is not always accurate. It used to be
    after running update statistics and after creating
    the table or its clustered index, and used to remain
    accurate as far as no serious problem or event
    happens: a shutdown with nowait, loading the database,
    a nasty error (stack trace and others).

    Queries can be coded to select the number of rows
    as sp_spaceused does. Thus, the same warning applies.

    select o.uid, o.name, rowcnt(i.doampg)
    from sysobjects o, sysindexes i
    where o.type='U' and o.id=i.id and
    i.indid <= 1

    Regards,
    Mariano Corral

Posting Permissions

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