DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Vincent Guest

    What is the fastest way to get row count in a table?


    Hi,

    Is there any other ways to get row count in a table without using this SQL
    statement : SELECT Count(*) FROM Table_Name ?

    Thanks!
    Vincent

  2. #2
    nick Guest

    Re: What is the fastest way to get row count in a table?


    sorry no way..look for easy ways in life!!!
    "Vincent" <vinc_ngd@hotmail.com> wrote:
    >
    >Hi,
    >
    >Is there any other ways to get row count in a table without using this SQL
    >statement : SELECT Count(*) FROM Table_Name ?
    >
    >Thanks!
    >Vincent



  3. #3
    davinci Guest

    Re: What is the fastest way to get row count in a table?


    If you are going to use this table in a recordset anyway you could get it
    through the count property. Of course for the count to be accurate here
    it needs to be a disconnected recordset or else you must move it to the last
    record first.

    The select count(*) should be a fast query though.

    "Vincent" <vinc_ngd@hotmail.com> wrote:
    >
    >Hi,
    >
    >Is there any other ways to get row count in a table without using this SQL
    >statement : SELECT Count(*) FROM Table_Name ?
    >
    >Thanks!
    >Vincent



  4. #4
    Narayana Pakala Guest

    Re: What is the fastest way to get row count in a table?


    "davinci" <spruett@lifeway.com> wrote:
    >
    >If you are going to use this table in a recordset anyway you could get it
    >through the count property. Of course for the count to be accurate here
    >it needs to be a disconnected recordset or else you must move it to the

    last
    >record first.
    >
    >The select count(*) should be a fast query though.
    >
    >"Vincent" <vinc_ngd@hotmail.com> wrote:
    >>
    >>Hi,
    >>
    >>Is there any other ways to get row count in a table without using this

    SQL
    >>statement : SELECT Count(*) FROM Table_Name ?
    >>
    >>Thanks!
    >>Vincent

    >


    Hello

    This works for Microsoft SQL Server. This assumes that you have a primary
    key for the table you want to know the total rows.

    Try the following query on Northwind database.

    SELECT si.rowcnt FROM sysindexes si INNER JOIN sysobjects so ON si.id = so.id
    WHERE si.rowcnt > 0 AND si.indid = 1 AND so.name = 'Order Details'
    go
    SELECT Count(*) FROM [Order Details]

    Both queries yield same result. Still the latter is simpler than the former.


    Don't let it bother you, the performance of Count(*) function is as much
    optimized as possible by all RDBMS products.

    Narayana


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links