count rows in single users database

This is an interesting little script by James Rea that will count the number of rows in each table in a specified database.

It might be useful in the future.  It extends count(*) to the entire database and not just a single table.  (Took me at least five minutes to realize that little fact…).  The output is sorted by count but the script is fulsomely commented and  there is a commented line to that will sort by table name rather than count.

The next, or final, comment is the description of the script as “records contained within any single user database” – i am scratching my head and trying to figure out why the database was forced into single-user mode and why databases would be set up this way and … finally looked at the code.  I would have written this as “count records in any selected user database” – not 100% certain that this is better, however the point is that the database is selected (use database…) and it is one at a time, not all user tables in all databases.  A SINGLE database, not a SINGLE USER database.