---
description: In this Cassandra TTL (Time To Live) tutorial, you will learn Cassandra Data Types, Cassandra Automatic Data Expiration using TTL with Syntax and Examples.
title: Cassandra TTL &#038; Cassandra CQL Data Types (Example)
image: https://www.guru99.com/images/cassandra-ttl-cql-data-types.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Cassandra Data Types define what each column may hold, and TTL controls how long a value survives before it expires automatically. This page lists every CQL type, explains the expiration mechanism, and covers the tombstone behaviour that follows expiry.

- 🔤 **Type Families:** CQL groups types into text, numeric, date and time, identifier, and collection categories.
- 🔢 **Numeric Choice:** tinyint through varint cover every integer width, while decimal preserves exact precision for money.
- 🆔 **UUID vs TimeUUID:** timeuuid embeds a timestamp and sorts chronologically, so it suits time-ordered clustering columns.
- ⏳ **TTL Basics:** A ttl value in seconds set at insert time deletes the data automatically once it elapses.
- 🪦 **Expiry Behaviour:** Expired data becomes a tombstone and is physically removed only after compaction.
- 🧊 **Frozen Types:** Marking a collection or tuple frozen stores it as one immutable value that must be replaced whole.

Read More

![Cassandra TTL CQL Data Types]()

## Cassandra Data Types

Cassandra supports different types of data types. Here is the table that shows data types, their constants, and description.

| CQL Type | Constants | Description |
| --- | --- | --- |
| ascii | Strings | US-Ascii character string |
| bigint | Integers | 64-bit signed long |
| blob | Blobs | Arbitrary bytes in hexadecimal |
| boolean | Booleans | True or false |
| counter | Integers | Distributed counter values 64 bit |
| date | Integers, strings | Calendar date with no time component |
| decimal | Integers, floats | Variable precision decimal |
| double | Integers, floats | 64-bit floating point |
| duration | Duration | A span of months, days, and nanoseconds |
| float | Integers, floats | 32-bit floating point |
| frozen | Tuples, collections, user defined types | Stores a multi-part value as one immutable blob |
| inet | Strings | IP address in IPv4 or IPv6 format |
| int | Integers | 32-bit signed integer |
| list |  | Ordered collection of elements |
| map |  | JSON style collection of key and value pairs |
| set |  | Unordered collection of unique elements |
| smallint | Integers | 16-bit signed integer |
| text | Strings | UTF-8 encoded string |
| time | Integers, strings | Time of day with nanosecond precision |
| timestamp | Integers, strings | Date plus time, encoded as milliseconds since epoch |
| timeuuid | UUIDs | Type 1 UUID, sortable by embedded time |
| tinyint | Integers | 8-bit signed integer |
| tuple |  | A fixed group of typed fields |
| uuid | UUIDs | Standard UUID |
| varchar | Strings | UTF-8 encoded string, an alias of text |
| varint | Integers | Arbitrary precision integer |

Three choices in that list cause most modelling mistakes, so they are worth stating explicitly.

- **text against varchar.** They are the same type. Either name works, and mixing them adds no value.
- **timestamp against timeuuid.** Use timestamp to record when something happened. Use timeuuid as a clustering column when many events share a millisecond, because the UUID guarantees uniqueness while still sorting by time.
- **decimal against double.** Monetary values belong in decimal. A double introduces binary rounding error that accumulates across aggregations.

A **counter** column carries a special restriction: a table may hold counter columns or ordinary columns, never both, and counter rows cannot be inserted, only incremented.

## Cassandra TTL (Time to Live) using Automatic Data Expiration

[Cassandra](https://www.guru99.com/cassandra-tutorial.html) provides functionality by which data can be automatically expired.

During data insertion, you have to specify ‘ttl’ value in seconds. ‘ttl’ value is the time to live value for the data. After that particular amount of time, data will be automatically removed.

For example, specify ttl value 100 seconds during insertion. Data will be automatically deleted after 100 seconds. When data is expired, that expired data is marked with a tombstone.

A tombstone exists for a grace period. After data is expired, data is automatically removed after compaction process.

**Syntax**

```
INSERT INTO KeyspaceName.TableName (ColumnNames)
VALUES (ColumnValues)
USING TTL TimeInSeconds;
```

**Example**

Here is the snapshot where data is being inserted in Student table with ttl value of 100 seconds.

[![Cassandra TTL using Automatic Data Expiration]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ27.png)

```
INSERT INTO University.Student (rollno, name, dept, semester)
VALUES (3, 'Guru99', 'CS', 7) USING TTL 100;
```

Here is the snapshot where data is automatically expired after 100 seconds and data is automatically removed.

[![Cassandra TTL using Automatic Data Expiration]()](https://www.guru99.com/images/cassandra/021116_1117_CassandraCQ28.png)

## Checking and Changing TTL on Existing Data

Once a value carries a TTL, three further operations are useful, and each has a behaviour that surprises newcomers.

The remaining lifetime of any non-primary-key column can be read with the TTL function.

```
SELECT name, TTL(name) FROM University.Student WHERE rollno = 3;
```

A null result means the column has no expiry set. Primary key columns cannot be queried this way, because the TTL attaches to the values rather than to the key.

An existing value can be given a new TTL by updating it, which resets the countdown from that moment.

```
UPDATE University.Student USING TTL 600
SET name = 'Guru99' WHERE rollno = 3;
```

A table-wide default avoids repeating the clause on every statement.

```
ALTER TABLE University.Student WITH default_time_to_live = 86400;
```

Two consequences follow. First, TTL applies per column, not per row, so updating one column without a TTL leaves that column behind after the rest expires, producing a partially populated row. Setting the TTL on the whole insert avoids this. Second, every expiry writes a tombstone, so a table where millions of rows expire together will slow reads until compaction clears them. Using TimeWindowCompactionStrategy for such tables lets whole SSTables be dropped at once rather than compacted row by row.

Expiry can also be applied to elements inside a collection, which is covered in the [Cassandra collections](https://www.guru99.com/cassandra-collections-tutorial-set-list-map.html) tutorial.

## FAQs

🔑 Can a TTL be applied to a primary key column?

No. TTL attaches to non-key values. A row disappears only once every non-key column has expired, so setting the TTL on the whole insert is the reliable approach.

⏰ What is the maximum TTL value?

The ceiling is 630,720,000 seconds, twenty years. Values above it are rejected, so longer retention must be handled by an application-level cleanup job.

🧊 When should a collection be frozen?

Freeze it when the whole value is always written together, or when it forms part of a primary key. A frozen collection cannot have individual elements updated.

🤖 Can AI pick the right CQL data type for a column?

Usually yes for obvious cases, but it commonly suggests double for money and uuid where timeuuid is needed for ordering. Check numeric precision and time ordering choices manually.

🧠 Can AI plan a TTL and retention strategy?

It can convert a retention policy into TTL values and recommend a compaction strategy. Confirm the legal retention period first, since expired data cannot be recovered.

#### 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-ttl-cql-data-types.png","url":"https://www.guru99.com/images/cassandra-ttl-cql-data-types.png","width":"700","height":"250","caption":"Cassandra TTL &amp; CQL Data Types","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.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-data-types-expiration-tutorial.html","name":"Cassandra TTL &#038; Cassandra CQL Data Types (Example)"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.html#webpage","url":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.html","name":"Cassandra TTL &#038; Cassandra CQL Data Types (Example)","dateModified":"2026-10-09T17:10:21+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/cassandra-ttl-cql-data-types.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.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 TTL &#038; Cassandra CQL Data Types (Example)","description":"In this Cassandra TTL (Time To Live) tutorial, you will learn Cassandra Data Types, Cassandra Automatic Data Expiration using TTL 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:21+05:30","image":{"@id":"https://www.guru99.com/images/cassandra-ttl-cql-data-types.png"},"copyrightYear":"2026","name":"Cassandra TTL &#038; Cassandra CQL Data Types (Example)","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can a TTL be applied to a primary key column?","acceptedAnswer":{"@type":"Answer","text":"No. TTL attaches to non-key values. A row disappears only once every non-key column has expired, so setting the TTL on the whole insert is the reliable approach."}},{"@type":"Question","name":"What is the maximum TTL value?","acceptedAnswer":{"@type":"Answer","text":"The ceiling is 630,720,000 seconds, twenty years. Values above it are rejected, so longer retention must be handled by an application-level cleanup job."}},{"@type":"Question","name":"When should a collection be frozen?","acceptedAnswer":{"@type":"Answer","text":"Freeze it when the whole value is always written together, or when it forms part of a primary key. A frozen collection cannot have individual elements updated."}},{"@type":"Question","name":"Can AI pick the right CQL data type for a column?","acceptedAnswer":{"@type":"Answer","text":"Usually yes for obvious cases, but it commonly suggests double for money and uuid where timeuuid is needed for ordering. Check numeric precision and time ordering choices manually."}},{"@type":"Question","name":"Can AI plan a TTL and retention strategy?","acceptedAnswer":{"@type":"Answer","text":"It can convert a retention policy into TTL values and recommend a compaction strategy. Confirm the legal retention period first, since expired data cannot be recovered."}}]}],"@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.html#schema-1151521","isPartOf":{"@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/cassandra-data-types-expiration-tutorial.html#webpage"}}]}
```
