How to get list of tables in each Keyspace in Cassandra - Cassandra / CQL Tutorial

How to get list of tables in each Keyspace in Cassandra by using Cassandra Query Language ( CQL)

Keyspace is container/ namespace in which we create tables in Cassandra. You can think of Keyspace as Schema in Relational Database Management System. Sometime we need to get the list of tables in each Keyspace or get count of tables in each Keyspace.
We can use system_schema.tables to get list of all tables with Keyspace names in which they exist.
CQLSH:techbrotherstutorials>SELECT keyspace_name, 
       table_name 
FROM   system_schema.tables;

I executed above query on Cassandra and got below results form my system.
Now if you are only interested to get the count of tables in each Keyspace, you can use below query.
CQLSH:techbrotherstutorials>SELECT   Count(*) AS Table_Count, 
         keyspace_name 
FROM     system_schema.tables 
GROUP BY keyspace_name;

The output of above query will be the count of tables in each keyspace in Cassandra.

1 comment: