문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 dba.stackexchange
scroll top