Working With UUID in Cassandra

Working With UUID in Cassandra

Instructor-svgAl-Mamun Sarkar
Sep 26 , 2020

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.

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram