List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 30 2002 4:53pm
Subject:Re: Number Of Records in a Table
View as plain text  
At 12:13 -0400 4/30/02, Andrew Kuebler wrote:
>Everyone on this list has been very helpful so far. I greatly appreciate
>all the help!
>I use Perl/DBI with MySQL. Normally to count records, I pull a query
>$a = $db->prepare("SELECT * FROM table");
>$numrows = $a->rows;


That's a bad idea for two reasons:
- It pulls the entire table over the network
- The rows() method for SELECT queries is deprecated in the DBI documentation

my $count = $db->selectrow_array ("SELECT COUNT(*) FROM tbl_name");

will give you what you want much more efficiently.

>to get a total count of records in the table. Is there an easier/faster
>way to do this if I'm looking only for the total record count for an
>entire table? On a large table, the operations above can be very time
>consuming & processor intensive. I know in the MySQL admin screen you
>can get the total # of items in a table as long as you have at least one
>column indexed & I would assume there is a way to extract that # from
>within Perl. Can anyone help?
>Thank you again!

Number Of Records in a TableAndrew Kuebler30 Apr
  • Re: Number Of Records in a TableShaun Bramley30 Apr
  • Re: Number Of Records in a TablePaul DuBois30 Apr