100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Cassandra Cheat Sheet

Cassandra Cheat Sheet

CQL syntax, data modeling concepts, consistency levels, and TTL usage for designing wide-column, horizontally scalable Cassandra tables.

2 PagesAdvancedFeb 25, 2026

cqlsh Basics

Connecting and exploring keyspaces.

sql
cqlsh localhost 9042DESCRIBE KEYSPACES;USE mykeyspace;DESCRIBE TABLE users;CREATE KEYSPACE mykeyspaceWITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};

CQL DDL & DML

Defining tables and reading/writing rows.

sql
CREATE TABLE users (  id UUID PRIMARY KEY,  email TEXT,  created_at TIMESTAMP);INSERT INTO users (id, email, created_at)VALUES (uuid(), 'a@b.com', toTimestamp(now()));SELECT * FROM usersWHERE id = 123e4567-e89b-12d3-a456-426614174000;UPDATE users SET email = 'x@y.com'WHERE id = 123e4567-e89b-12d3-a456-426614174000;

Data Modeling Concepts

Key ideas behind Cassandra's distributed model.

  • Partition key- determines which node(s) store the row; drives data distribution
  • Clustering key- sorts rows within a partition on disk
  • Wide row- a table with many clustering columns, common for time-series data
  • Denormalization- duplicating data per query pattern since Cassandra has no JOINs
  • Consistency level- ONE, QUORUM, ALL — trades off latency against read/write consistency
  • Compaction strategy- SizeTieredCompactionStrategy vs LeveledCompactionStrategy for SSTable merging

Consistency & TTL

Session consistency and automatic row expiry.

sql
-- Set consistency level for the cqlsh sessionCONSISTENCY QUORUM;-- Row automatically expires after 3600 secondsINSERT INTO users (id, email) VALUES (uuid(), 'a@b.com') USING TTL 3600;-- Check remaining TTL on a columnSELECT TTL(email) FROM usersWHERE id = 123e4567-e89b-12d3-a456-426614174000;
Pro Tip

Design tables around your queries, not your entities — Cassandra has no JOINs, so the standard rule of thumb is one denormalized table per query pattern.

Was this cheat sheet helpful?

Explore Topics

#Cassandra#CassandraCheatSheet#Database#Advanced#CqlshBasics#CQLDDLDML#DataModelingConcepts#ConsistencyTTL#Databases#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet