TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Cassandra Tutorial

Cassandra Create Table for beginners and professionals with topics on architecture, relational vs no sql database, data model, cql, cqlsh, keyspace operations, table operations, installation, collections etc.

<< Back to CASSANDRA

Cassandra Create Table

In Cassandra, CREATE TABLE command is used to create a table. Here, column family is used to store data just like table in RDBMS.

So, you can say that CREATE TABLE command is used to create a column family in Cassandra.

Syntax:

CREATE (TABLE | COLUMNFAMILY) <tablename>
('<column-definition>' , '<column-definition>')
(WITH <option> AND <option>) 

Or

For declaring a primary key:

CREATE TABLE tablename(
   column1 name datatype PRIMARYKEY,
   column2 name data type,
   column3 name data type.
   )

You can also define a primary key by using the following syntax:

Create table TableName
(
ColumnName DataType,
ColumnName DataType,
ColumnName DataType
.
.
.
Primary key(ColumnName)
) with PropertyName=PropertyValue; 

There are two types of primary keys:

  • Single primary key: Use the following syntax for single primary key.
  • Primary key (ColumnName) 
    
  • Compound primary key: Use the following syntax for single primary key.
  • Primary key(ColumnName1,ColumnName2 . . .)  
    

    Example:

    Let's take an example to demonstrate the CREATE TABLE command.

    Here, we are using already created Keyspace "TheDeveloperBlog".

    CREATE TABLE student(
       student_id int PRIMARY KEY,
       student_name text,
       student_city text,
       student_fees varint,
       student_phone varint
       ); 
    
    Cassandra Create table 1

    The table is created now. You can check it by using the following command.

    SELECT * FROM student;
    
    Cassandra Create table 2




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf