Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 2.23 KB

File metadata and controls

76 lines (64 loc) · 2.23 KB
Tables with Single-Row Partitions in Apache Cassandra® ℹ️ For technical support, please contact us via email or LinkedIn.
⬅️ Back Step 5 of 9 Next ➡️
Create table "movies"

Our second table will store information about movies as shown below. To define this table with single-row partitions, we can use title and year as a composite partition key.

title year duration avg_rating
Alice in Wonderland 2010 108 6.00
Alice in Wonderland 1951 75 7.08

✅ Create the table:

CREATE TABLE IF NOT EXISTS movies (
  title TEXT,
  year INT,
  duration INT,
  avg_rating FLOAT,
  PRIMARY KEY ((title, year))
);

✅ Insert the rows:

INSERT INTO movies (title, year, duration, avg_rating) 
VALUES ('Alice in Wonderland', 2010, 108, 6.00);
INSERT INTO movies (title, year, duration, avg_rating) 
VALUES ('Alice in Wonderland', 1951, 75, 7.08);

✅ Retrieve one row:

SELECT * FROM movies
WHERE title = 'Alice in Wonderland'
  AND year = 2010;

✅ Retrieve all rows:

SELECT * FROM movies;
⬅️ Back Next ➡️