• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Count total number of records in database

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you count the total number of records in your database.
Probably something simple query called COUNT.
Could someone tell me the syntax for this, and how do you then display the result of your count?
Many thanks.
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, for a single table, to count the number of rows you issue:
select count(*) from mytable
But to count the number of rows in your entire database (do you really need to know this?), you first need to determine the tables, and then issue the same select statement above.
To find the names of tables in a database is usually vendor specific, eg. in oracle there are numerous ways to do it, but a common one is:
select * from cat
Also to keep in mind, depending what user you used to connect to the database, may affect which tables you have access to.
Also, in JDBC, there is a method on the java.sql.Connection interface to retrieve the metadata for the database (getMetaData()), and in the java.sql.DatabaseMetaData interface you should find some methods for retrieving the tables within the database.
So the pseudo code would be:


In case I have gone way off the mark, and you just need code for rows in 1 table:

[ March 05, 2004: Message edited by: James Swan ]
 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I just needed the number of rows in onw table.
 
reply
    Bookmark Topic Watch Topic
  • New Topic