Kangkan Lahkar
Kangkan Lahkar

Reputation: 317

How to obtain number of tables in a keyspace in Cassandra?

For example, we can use

select count(*) from student_database;

to calculate the number of rows in a table. But how do we calculate the number of tables in a keyspace?

DESCRIBE TABLES;

gives you the list of all tables in that keyspace.

Upvotes: 3

Views: 3027

Answers (3)

ruyaenes
ruyaenes

Reputation: 1

rows = session.execute("SELECT count(*) FROM system_schema.tables WHERE keyspace_name = 'your_keyspace_name'")

print(list(rows))

Result:

[Row(count=2)]

Upvotes: 0

Aaron
Aaron

Reputation: 57798

And for a Cassandra 2.x (and lower) answer:

SELECT COUNT(*) FROM system.schema_columnfamilies 
    WHERE keyspace_name='your keyspace';

Upvotes: 3

undefined_variable
undefined_variable

Reputation: 6228

SELECT count(*) FROM system_schema.tables WHERE keyspace_name='your keyspace'

The above query will work in cassandra 3.0 and above

Upvotes: 3

Related Questions