cyclist_id

Composite partition key example with a clustering column.

SOURCE 'keyspace-create-simple.cql';
SOURCE 'keyspace-use.cql';

// tag::table-drop-cyclist-id[] 
DROP TABLE IF EXISTS cycling.cyclist_id;
// end::table-drop-cyclist-id[]

// Find cyclist id given lastname and firstname
// Another CREATE TABLE using COMPOSITE PARTITION KEY
// INDEX ALSO GOOD FOR THIS TABLE

// Composite partition key example without a clustering column
// tag::table-create-cyclist-id-no-clustering-column[]
CREATE TABLE IF NOT EXISTS cycling.cyclist_id (
  lastname text,
  firstname text,
  age int,
  id uuid,
  PRIMARY KEY ((lastname, firstname))
);
// end::table-create-cyclist-id-no-clustering-column[]

// LLP: if this file is run in test, add a DROP TABLE between
// these CREATE TABLE statements

// Composite partition key example with a clustering column on age
// tag::comp_pk[]
CREATE TABLE IF NOT EXISTS cycling.cyclist_id (
  lastname text,
  firstname text,
  age int,
  id UUID,
  PRIMARY KEY ((lastname, firstname), age)
);
// end::comp_pk[]

// tag::altercdc[]
ALTER TABLE cycling.cyclist_id
WITH CDC = false;
// end::altercdc[]

// tag::insert-cyclist-id[]
INSERT INTO cycling.cyclist_id (
  lastname, firstname, age, id
) VALUES (
  'EENKHOORN', 'Pascal', 18, ffdfa2a7-5fc6-49a7-bfdc-3fcdcfdd7156
);

INSERT INTO cycling.cyclist_id (
  lastname, firstname, age, id
) VALUES (
  'WELTEN', 'Bram', 18, 18f471bf-f631-4bc4-a9a2-d6f6cf5ea503
);

INSERT INTO cycling.cyclist_id (
  lastname, firstname, age, id
) VALUES (
  'COSTA', 'Adrien', 17, 15a116fc-b833-4da6-ab9a-4a7775752836
);
// end::insert-cyclist-id[]

// attempt to delete data using IF EXISTS, applied false because Bram Jones does not exist
CAPTURE 'cyclist_id_delete_if_exists.results';
// tag::deleteifexists[]
DELETE id FROM cycling.cyclist_id 
WHERE lastname = 'JONES'
  AND firstname = 'Bram' 
IF EXISTS;
// end::deleteifexists[]
CAPTURE OFF;

// tag::resetid[]
UPDATE cycling.cyclist_id 
SET id = UUID() 
WHERE lastname = 'WELTEN'
  AND firstname = 'Bram'
  AND age = 18
IF EXISTS;
// end::resetid[]

// tag::ifid[]
UPDATE cycling.cyclist_id 
SET id = UUID() 
WHERE lastname = 'WELTEN'
  AND firstname = 'Bram'
  AND age = 18
IF id = 18f471bf-f631-4bc4-a9a2-d6f6cf5ea503;
// end::ifid[]

// tag::ifnull[]
UPDATE cycling.cyclist_id 
SET id = UUID() 
WHERE lastname = 'Smith'
  AND firstname = 'Joe'
  AND age = 22
IF id = NULL;
// end::ifnull[]

// tag::basicwhere[]
SELECT
  firstname AS first,
  lastname AS last
FROM cycling.cyclist_id
WHERE lastname = 'COSTA'
  AND firstname = 'Adrien';
// end::basicwhere[]

// tag::select_with_in_and_equals[]
SELECT * 
FROM cycling.cyclist_id 
WHERE lastname = 'EENKHOORN'
  AND firstname = 'Pascal'
  AND age IN (17, 18); 
// end::select_with_in_and_equals[]

// delete data using an IF, age does not match so applied is false
CAPTURE 'cyclist_id_delete_if.results';
// tag::deletedataif[]
DELETE id FROM cycling.cyclist_id 
WHERE lastname = 'WELTEN'
  AND firstname = 'Bram' 
IF age = 20;
// end::deletedataif[]
CAPTURE OFF;

Queries

SELECT
  firstname AS first,
  lastname AS last
FROM cycling.cyclist_id
WHERE lastname = 'COSTA'
  AND firstname = 'Adrien';

Composite partition key example without a clustering column.

CREATE TABLE IF NOT EXISTS cycling.cyclist_id (
  lastname text,
  firstname text,
  age int,
  id uuid,
  PRIMARY KEY ((lastname, firstname))
);

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com