How Do You Run Some Cassandra Commands to Create a Table?

Problem scenario
You want to create a table in Cassandra.  How do you do this?

Solution
Prerequisites
Install and configure Cassandra.  If you do not know how, click on the link for the distribution of Linux that you have:

Debian or Ubuntu
CentOS/RHEL/Fedora
SUSE

Procedures
You will have to create a keyspace, then use it, then create a table.

1.  Enter the cqlsh command prompt (e.g., with cqlsh).

2.  Run this command to create the keyspace:

CREATE KEYSPACE contint WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 2 } AND DURABLE_WRITES = false;

3.  Enter the keyspace with this command:

USE test

4.  Create the table with this command:
CREATE TABLE contint(
   contint_id int PRIMARY KEY,
   contint_name text,
   contint_city text,
   contint_sal varint,
   contint_phone varint
   );

Leave a comment

Your email address will not be published. Required fields are marked *