Count Rows Per Table in an Oracle Schema

Today I had this problem, Trying to reverse engineer this database, but most of the tables in our deployment aren’t used, they are there but they aren’t used and to be able to properly do this task I was assigned I needed to concentrate on the tables that are actually being used.

To solve this issue I decided to count the rows in every table in the oracle schema, so I can decide which tables I should focus on, first I attempted to do it through a clever PL/SQL script and then out of cheer frustration I decided to opt for a simple brute force solution.

First you run this:

select ‘select ”’||table_name||”’, count(*) from ‘||owner||’.’||table_name||’;’ from all_tables where owner = ‘&SCHEMA’;

Then run the resulting commands, and voila you’ve got the row count per table you were looking for. Simple and Straight forward.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s