• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Count total number of records in database

 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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.
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you. I just needed the number of rows in onw table.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic