Working With UUID in Cassandra

Author: Al-mamun Sarkar Date: 2020-09-26 07:21:32

In this lesson, I will show you how to create a table with UUID PRIMARY KEY and how to insert UUID.

Create Table With UUID:

CREATE TABLE employee_by_uuid (
   id uuid PRIMARY KEY,
   first_name text,
   last_name text
);

Insert Data:

INSERT INTO employee_by_uuid (id, first_name, last_name)
VALUES (uuid(), 'Jone', 'Doe');

Check Inserted Data:

SELECT * FROM employee_by_uuid;

 

 Create Table With Time UUID:

CREATE TABLE employee_by_timeuuid (
   id timeuuid PRIMARY KEY,
   first_name text,
   last_name text
);

Insert Data:

INSERT INTO employee_by_timeuuid (id, first_name, last_name)
VALUES (now(), 'Jone', 'Doe');

Check Inserted Data:

SELECT * FROM employee_by_timeuuid;

We will be able to sort by creation time of id if we use timeuuid.