2

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.

Community
  • 1
  • 1
Kangkan Lahkar
  • 267
  • 5
  • 16

3 Answers3

3

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

SELECT COUNT(*) FROM system.schema_columnfamilies 
    WHERE keyspace_name='your keyspace';
Aaron
  • 55,518
  • 11
  • 116
  • 132
2

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

The above query will work in cassandra 3.0 and above

undefined_variable
  • 6,180
  • 2
  • 22
  • 37
  • Can you please help me in this answer for cassandra 3.0 and above... http://stackoverflow.com/questions/42469341/how-do-i-retrieve-table-names-in-cassandra-using-java – Kangkan Lahkar Feb 26 '17 at 18:06
0
rows = session.execute("SELECT count(*) FROM system_schema.tables WHERE keyspace_name = 'your_keyspace_name'")

print(list(rows))

Result:

[Row(count=2)]
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • Answers should mention how the code works not just provide the solution in code. – Shawn Nov 26 '20 at 00:52
  • This query works only for specific versions of the Cassandra. If you're using Python, then you need to use functionality of the driver that works with different Cassandra versions – Alex Ott Nov 26 '20 at 09:18