Question

How to do that? I was thinking of something like:

SELECT COUNT(A.table_name), COUNT(B.table_name)
FROM information_schema.tables AS A, information_schema.views AS B;

But sadly it gives me bad numbers (it multiplies the first COUNT with the second one) and I still don't know how to get BASE TABLES.

Was it helpful?

Solution

information_schema.tables includes tables and views, so you only need:

select count(*)
from information_schema.tables
where table_type in ('VIEW', 'BASE TABLE')

If you want the numbers separately for each type, use a group by

select table_type, count(*)
from information_schema.tables
where table_type in ('VIEW', 'BASE TABLE')
group by table_type

The reason your statement isn't working is because you are creating a cross join (cartesian product) between the two system view.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top