---
description: Cassandra Create Table tutorial explains How to Create, Alter, Drop, Truncate Tables in Cassandra with Syntax and Examples.
title: "Cassandra CQL Table: Create, Alter &#038; Truncate Example"
image: https://www.guru99.com/images/cassandra-table-create-alter-drop.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Cassandra Table operations cover creating, altering, dropping, and truncating column families with CQL. This page explains each command, the three primary key forms that decide data distribution, and the differences between removing rows and removing a table.

- 🏗️ **Create Table:** A table needs a keyspace, column definitions, and a primary key clause that fixes distribution and sort order.
- 🔑 **Single Primary Key:** One column acts as the partition key, so every row of that value lands on the same node.
- 🧩 **Compound Primary Key:** The first column partitions, the remaining columns cluster and sort rows inside the partition.
- 🧮 **Compound Partition Key:** Bracketing two columns splits an oversized partition into many smaller ones.
- ✏️ **Alter Limits:** Columns can be added or dropped, but primary key columns can never be altered.
- 🗑️ **Drop vs Truncate:** Drop removes the schema and data; truncate empties every row but keeps the table definition.

Read More

![Cassandra Table Create Alter Drop](https://www.guru99.com/images/cassandra-table-create-alter-drop.png)

The syntax of Cassandra query language (CQL) resembles [SQL](https://www.guru99.com/sql.html) language.

## How to Create Table in Cassandra

Column family in Cassandra is similar to RDBMS table. Column family is used to store data.

Command ‘Create Table’ is used to create column family in Cassandra.

### Syntax

```
CREATE TABLE KeyspaceName.TableName (
    ColumnName DataType,
    ColumnName DataType,
    ColumnName DataType,
    PRIMARY KEY (ColumnName)
) WITH PropertyName = PropertyValue;
```

**1. Primary key:** There are two types of [primary key](https://www.guru99.com/difference-between-primary-key-and-foreign-key.html).

- **Single Primary Key:** Single primary key is specified by the following syntax.

### Syntax

```
PRIMARY KEY (ColumnName)
```

In the single primary key, there is only a single column. That column is also called partitioning key. Data is partitioned on the basis of that column. Data is spread on different nodes on the basis of the partition key.

**2. Compound Primary Key:** Compound primary key is specified by the following syntax.

### Syntax

```
PRIMARY KEY (ColumnName1, ColumnName2, ...)
```

In above syntax, ColumnName1 is the partitioning key and ColumnName2 is the Clustering key. Data will be partitioned on the basis of ColumnName1 and data will be clustered on the basis of ColumnName2. Clustering is the process that sorts data in the partition.

**3. Compound Partitioning key:** Compound partitioning key is specified by the following syntax.

### Syntax

```
PRIMARY KEY ((ColumnName1, ColumnName2), ColumnName3)
```

In above syntax, ColumnName1 and ColumnName2 are the compound partition key. Data will be partitioned on the basis of both columns ColumnName1 and ColumnName2 and data will be clustered on the basis of the ColumnName3. If you have too much data on the single partition, then compound partitioning key is used. Compound partitioning key is used to create multiple partitions for the data.

- **With Clause**

“With clause” is used to specify any property and its value for the defined table. For example, if you want to compress Cassandra table data. You can set compression property by specifying compression algorithm property value in “With clause.” The same clause also sets CLUSTERING ORDER BY to reverse the sort direction of a clustering column, and default\_time\_to\_live to expire every row automatically.

**Don't Miss:**

- [How to Download & Install Cassandra on Windows](https://www.guru99.com/download-install-cassandra.html)
- [Create and Drop INDEX in Cassandra](https://www.guru99.com/create-drop-index-in-cassandra-complete-tutorial.html)
- [Cassandra TTL & Cassandra CQL Data Types (Example)](https://www.guru99.com/cassandra-data-types-expiration-tutorial.html)
- [Top 23 Cassandra Interview Questions and Answers (2026)](https://www.guru99.com/cassandra-interview-questions.html)

### Example

Here is the execution of the command ‘Create table’ that will create table name ‘Student’ in the keyspace ‘University.’

[![Cassandra Create Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ5.png)

```
CREATE TABLE University.Student (
    RollNo int,
    Name text,
    dept text,
    PRIMARY KEY (RollNo)
);
```

After successful execution of the command ‘Create table’, table ‘Student’ will be created in the keyspace ‘University’ with columns RollNo, Name and dept. RollNo is the primary key. RollNo is also a partition key, so each student occupies a separate single-row partition.

## Cassandra Alter table

Command ‘Alter Table’ is used to drop column, add a new column, alter column name, alter column type and change the property of the table.

### Syntax

Following is the syntax of command ‘Alter Table.’

```
ALTER TABLE KeyspaceName.TableName
    ADD ColumnName ColumnDataType;

ALTER TABLE KeyspaceName.TableName
    DROP ColumnName;

ALTER TABLE KeyspaceName.TableName
    RENAME ColumnName TO NewColumnName;

ALTER TABLE KeyspaceName.TableName
    WITH PropertyName = PropertyValue;
```

Each form is issued as a separate statement. Two restrictions apply in current Cassandra releases: the data type of an existing column can no longer be changed, and RENAME works only on a clustering column of the primary key.

### Example

Here is the snapshot of the command ‘Alter Table’ that will add new column in the table Student.

[![Cassandra Alter table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ6.png)

```
ALTER TABLE University.Student ADD Semester int;
```

After successful execution of the command ‘Alter Table’, a new column ‘Semester’ with ‘int’ data type will be added to the table Student.

Here is the screenshot that shows the updated Student table.

[![Cassandra Alter table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ7.png)

## Cassandra Drop Table

Command ‘Drop table’ drops specified table including all the data from the keyspace. Before dropping the table, Cassandra takes a snapshot of the data not the schema as a backup.

### Syntax

```
DROP TABLE IF EXISTS KeyspaceName.TableName;
```

### Example

Here is the snapshot of the executed command ‘Drop Table’ that will drop table Student from the keyspace ‘University’.

[![Cassandra Drop Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ8.png)

```
DROP TABLE University.Student;
```

After successful execution of the command ‘Drop Table’, table Student will be dropped from the keyspace University.

Here is the snapshot that shows the error returned by the Cassandra when tried to access Student table that does not exist.

[![Cassandra Drop Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ9.png)

## Cassandra Truncate Table

Command ‘Truncate table’ removes all the data from the specified table. Before truncating the data, [Cassandra](https://www.guru99.com/cassandra-tutorial.html) takes the snapshot of the data as a backup.

### Syntax

```
TRUNCATE KeyspaceName.TableName;
```

### Example

There are three records in the table Student. These are the records in the table.

[![Cassandra Truncate Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ10.png)

Here is the snapshot of the executed command ‘Truncate table’ that will remove all the data from the table Student.

[![Cassandra Truncate Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ11.png)

After successful execution of the command ‘Truncate Table’, all the data will be removed from the table Student.

Here is the snapshot of the database state where there are no records in the table Student.

[![Cassandra Truncate Table]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ12.png)

Truncate requires every node to be reachable, because it is executed across the whole cluster at once. If any node is down the statement fails, which is a deliberate safeguard against leaving partial data behind.

## Drop vs Truncate vs Delete in Cassandra

Three commands remove data, and choosing the wrong one either destroys a schema or leaves a performance problem behind.

| Command | What it removes | Schema kept | Cost |
| --- | --- | --- | --- |
| **DROP TABLE** | All rows and the table definition | No | Cheap. SSTables are snapshotted then discarded. |
| **TRUNCATE** | All rows | Yes | Cheap, but needs every node up. No tombstones are created. |
| **DELETE** | Selected rows or columns | Yes | Expensive at scale. Each removal writes a tombstone that reads must skip until compaction. |

The practical rule is to prefer TRUNCATE over a bulk DELETE when clearing an entire table, because thousands of tombstones will slow every subsequent read of that partition. Row-level removal is covered in the [CQL insert, update and delete](https://www.guru99.com/cassandra-query-language-cql-insert-update-delete-read-data.html) tutorial.

## FAQs

🔑 Can the primary key be changed after a table is created?

No. The primary key determines physical data placement, so it is fixed at creation. Changing it means creating a new table with the desired key and migrating the rows across.

🧭 How is the sort order inside a partition reversed?

Add WITH CLUSTERING ORDER BY (ColumnName DESC) at creation time. Setting it in the schema is far cheaper than sorting at query time on every read.

📦 Does dropping a column free disk space immediately?

No. The column is hidden from queries at once, but its data remains inside existing SSTables until compaction rewrites them. Space is reclaimed gradually.

🤖 Can AI convert a SQL CREATE TABLE into CQL?

The column list translates cleanly, but AI often keeps a surrogate id as the partition key, which creates single-row partitions. Restate the query pattern so the key is chosen for reads.

🧠 Can AI review a CQL schema for problems?

Yes, for pattern-level issues such as missing clustering columns, unbounded partitions, or collection columns likely to exceed limits. Confirm against real cardinality before acting.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/cassandra-table-create-alter-drop.png","url":"https://www.guru99.com/images/cassandra-table-create-alter-drop.png","width":"700","height":"250","caption":"Cassandra Table - Create, Alter, Drop","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/cassandra","name":"Cassandra"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html","name":"Cassandra CQL Table: Create, Alter &#038; Truncate Example"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#webpage","url":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html","name":"Cassandra CQL Table: Create, Alter &#038; Truncate Example","dateModified":"2026-10-09T17:10:09+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/cassandra-table-create-alter-drop.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Cassandra","headline":"Cassandra CQL Table: Create, Alter &#038; Truncate Example","description":"Cassandra Create Table tutorial explains How to Create, Alter, Drop, Truncate Tables in Cassandra with Syntax and Examples.","keywords":"cassandra","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-09T17:10:09+05:30","image":{"@id":"https://www.guru99.com/images/cassandra-table-create-alter-drop.png"},"copyrightYear":"2026","name":"Cassandra CQL Table: Create, Alter &#038; Truncate Example","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can the primary key be changed after a table is created?","acceptedAnswer":{"@type":"Answer","text":"No. The primary key determines physical data placement, so it is fixed at creation. Changing it means creating a new table with the desired key and migrating the rows across."}},{"@type":"Question","name":"How is the sort order inside a partition reversed?","acceptedAnswer":{"@type":"Answer","text":"Add WITH CLUSTERING ORDER BY (ColumnName DESC) at creation time. Setting it in the schema is far cheaper than sorting at query time on every read."}},{"@type":"Question","name":"Does dropping a column free disk space immediately?","acceptedAnswer":{"@type":"Answer","text":"No. The column is hidden from queries at once, but its data remains inside existing SSTables until compaction rewrites them. Space is reclaimed gradually."}},{"@type":"Question","name":"Can AI convert a SQL CREATE TABLE into CQL?","acceptedAnswer":{"@type":"Answer","text":"The column list translates cleanly, but AI often keeps a surrogate id as the partition key, which creates single-row partitions. Restate the query pattern so the key is chosen for reads."}},{"@type":"Question","name":"Can AI review a CQL schema for problems?","acceptedAnswer":{"@type":"Answer","text":"Yes, for pattern-level issues such as missing clustering columns, unbounded partitions, or collection columns likely to exceed limits. Confirm against real cardinality before acting."}}]}],"@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#schema-1151493","isPartOf":{"@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/cassandra-table-create-alter-drop-truncate.html#webpage"}}]}
```
