🧚 注目!Beekeeper Studioは高速でモダン、オープンソースのデータベースGUIです ダウンロード
May 8, 2024 著者: Matthew Rathbone

Apache Cassandra is a distributed NoSQL database designed to handle large amounts of data across many commodity servers without any single point of failure. One of the initial steps when working with Cassandra is listing the tables within a keyspace. This tutorial will cover how to show tables in Cassandra using CQL (Cassandra Query Language).

Prerequisites

Before you start, ensure you have:

  • Apache Cassandra installed and running.
  • cqlsh (Cassandra Query Language Shell) available for running CQL commands.

Connecting to Cassandra Using cqlsh

To begin, start the cqlsh shell. Open your terminal and type:

cqlsh

You should see a prompt indicating you are now connected to Cassandra:

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 6.0.0 | Cassandra 4.0.0 | CQL spec 3.4.5 | Native protocol v4]
Use HELP for help.
cqlsh>

Listing Keyspaces

Before listing tables, it is helpful to know which keyspaces exist. Keyspaces are Cassandra’s equivalent of databases in a relational database system. To list all keyspaces, use:

DESCRIBE KEYSPACES;

The expected output will look something like this (the actual keyspaces will depend on your setup):

system
system_auth
system_distributed
system_schema
system_traces
my_keyspace

Switching to the Desired Keyspace

You need to switch to the keyspace containing the tables you wish to list. For this example, we’ll assume you have a keyspace named my_keyspace. Switch to it using:

USE my_keyspace;

Listing Tables in a Keyspace

To show all tables within the current keyspace, you can use the following command:

DESCRIBE TABLES;

This command will list all the tables within the keyspace. Here is an example of the output you might see:

users
products
orders

Detailed Table Information

To get more detailed information about a specific table, such as its schema, use the DESCRIBE command followed by the table name:

DESCRIBE TABLE users;

The expected output will look something like this:

CREATE TABLE my_keyspace.users (
    user_id uuid PRIMARY KEY,
    first_name text,
    last_name text,
    email text
) WITH ...

This output includes the full CQL command to create the table, along with its properties.

Conclusion

Listing tables in Apache Cassandra is a straightforward process. By following this guide, you can quickly navigate through keyspaces and retrieve table information using CQL commands. This foundational knowledge is essential for managing and interacting with data stored in Cassandra. Happy querying!

Beekeeper Studioは無料でオープンソースのデータベースGUIです

今まで使った中で最高のSQLクエリ&エディタツールです。データベース管理に必要なすべてが揃っています。 - ⭐⭐⭐⭐⭐ Mit

Beekeeper Studioは高速で直感的、使いやすいです。Beekeeperは多くのデータベースをサポートし、Windows、Mac、Linuxで快適に動作します。

BeekeeperのLinux版は100%フル機能で、機能の妥協はありません。

Beekeeper Studioについてユーザーの声

★★★★★
"Beekeeper Studioは私の古いCassandraワークフローを完全に置き換えました。高速で直感的で、データベース作業を再び楽しくしてくれます。"
— Alex K.、データベース開発者
★★★★★
"多くのデータベースGUIを試しましたが、Beekeeperは機能とシンプルさの完璧なバランスを実現しています。とにかく動きます。"
— Sarah M.、フルスタックエンジニア

Cassandraワークフローを改善する準備はできましたか?

download 無料ダウンロード