liveBook · Manning

CREATE TABLE statement

As explained in ScyllaDB in Action

A CREATE TABLE statement is a CQL schema-definition command that creates a table with columns and keys.

A CREATE TABLE statement defines a ScyllaDB table by combining the application design with column names, data types, and a primary key. In the restaurant-review application, it turns planned access patterns into runnable tables. section 5.3 section 2.5

A table definition specifies:

  • Columns such as TIMEUUID identifiers, TEXT fields, TINYINT scores, DATE values, and collections of frozen user-defined values. section 5.3.1
  • A primary key that identifies rows and determines partitioning and sorting; the first key component serves as the partition key. section 2.5
  • Optional clustering order, such as id DESC, for returning recent summaries first within author, date, or score partitions. section 5.3.2

Articles table

After creating the image user-defined type, create the main review table with the article identifier as its primary key: CREATE TABLE reviews.articles(id TIMEUUID, title TEXT, author_id TIMEUUID, score TINYINT, date DATE, images SET<FROZEN<image>>, review TEXT, restaurant_name TEXT, PRIMARY KEY (id)); section 5.3.1

Listing 5.3 Building the articles table from your design
cqlsh: reviews> CREATE TABLE reviews.articles(
    id TIMEUUID,
    title TEXT,
    author_id TIMEUUID,
    score TINYINT,
    date DATE,
    images SET<FROZEN<image>>,
    review TEXT,
    restaurant_name TEXT,
    PRIMARY KEY (id)
);

Inspect the complete articles-table listing, including its columns, collection type, and primary-key declaration. section 5.3.1

How ScyllaDB in Action covers it

How deep it goes
Explains columns, types, primary keys, partitions, and clustering order through complete tables, without covering later reads or writes in detail.
Examples
Uses articles, authors, and summary tables organized by author, date bucket, and score.
What it assumes
Assumes a designed schema and teaches required columns, types, keys, and a preceding image user-defined type.
What you can do after
Build tables from an application design using runnable CQL in cqlsh.
How it connects
Connects CQL with keyspaces, primary keys, partition keys, clustering order, and user-defined types.

Also explained in

Compare how 6 books explain CREATE TABLE statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.