CQL quick reference

See this quick reference guide for other CQL versions: 5.1 | 6.0.

Download a printable CQL reference with the ten most frequently use CQL commands and a list of the CQL data types.

ALTER TABLE

ALTER TABLE [<keyspace_name>.]<table_name>
  [ ADD ( <column_definition> | <column_definition_list> ) [ , ... ] ]
  [ DROP <column_name> [ , ... ] ]
  [ [ RENAME <column_name> TO <column_name> ] |
    [ RENAME ( VERTEX LABEL | EDGE LABEL ) TO <new_name> ] ]
  [ WITH <table_properties> [ , ... ] ]
  [ WITH ( VERTEX LABEL | EDGE LABEL ) <current_name> ]
  [ WITHOUT ( VERTEX LABEL | EDGE LABEL ) <current_name> ];

ALTER TYPE

ALTER TYPE <field_name>
  ( ADD <field_name> <cql_datatype>
  | RENAME <field_name> TO <<<new_field_name> [ AND <field_name> TO <new_field_name> ...] ) ;

BATCH

BEGIN [ ( UNLOGGED | LOGGED ) ] BATCH
  [ USING TIMESTAMP [ <epoch_microseconds> ] ]
  <dml_statement> [ USING TIMESTAMP [ <epoch_microseconds> ] ] ;
  [ <dml_statement> [ USING TIMESTAMP [ <epoch_microseconds> ] ] [ ; ... ] ] ;
  APPLY BATCH ;

CREATE CUSTOM INDEX

CREATE CUSTOM INDEX [ IF NOT EXISTS ] [ <index_name> ]
  ON [ <keyspace_name>.]<table_name> (<column_name>)
    | [ (KEYS(<map_name>)) ]
    | [ (VALUES(<map_name>)) ]
    | [ (ENTRIES(<map_name>)) ]
  USING 'StorageAttachedIndex'
  [ WITH OPTIONS = { <option_map> } ] ;

CREATE FUNCTION

CREATE [ OR REPLACE ] FUNCTION [ IF NOT EXISTS ] [<keyspace_name>]<function_name> (<argument_list> [ , ... ])
  ( CALLED | RETURNS NULL ) ON NULL INPUT RETURNS <type>
  [ DETERMINISTIC ]
  [ MONOTONIC [ ON <argument_name> ] ]
  LANGUAGE ( java | javascript ) AS $$ <code_block> $$ ;

CREATE INDEX

CREATE INDEX [ IF NOT EXISTS ] <index_name>
  ON [<keyspace_name>.]<table_name>
  ([ ( KEYS | FULL ) ] <column_name>)
  (ENTRIES <column_name>) ;

CREATE TABLE

CREATE TABLE [ IF NOT EXISTS ] [<keyspace_name>.]<table_name>
  ( <column_definition> [ , ... ] | PRIMARY KEY (column_list) )
  [ WITH [ <table_options> ]
  [ [ AND ] CLUSTERING ORDER BY [ <clustering_column_name> <order> ] ]
  [ AND ( VERTEX LABEL <vl_name> | EDGE LABEL ) <el_name> FROM <vl_name> TO <vl_name>]
  [ [ AND ] ID = '<table_hash_tag>' ] ] ;

CREATE TYPE

CREATE TYPE [ IF NOT EXISTS ] [<keyspace_name>].<type_name>
  (<field_name> <cql_datatype> [ , <field_name> <cql_datatype> ... ]) ;

DELETE

DELETE [ <column_name> [ <term> ] [ , ... ] ]
  FROM [<keyspace_name>.]<table_name>
  [ USING TIMESTAMP <timestamp_value> ]
  WHERE <PK_column_conditions>
  [ ( IF EXISTS | IF <static_column_conditions> ) ] ;

DROP INDEX

DROP INDEX [ IF EXISTS ] [<keyspace_name>.]<index_name> ;

DROP TABLE

DROP TABLE [ IF EXISTS ] [<keyspace_name>.]<table_name> ;

DROP TYPE

DROP TYPE [ IF EXISTS ] [<keyspace_name>.]<type_name> ;

GRANT

GRANT <permission>
  ON <object>
  TO <role_name> ;

INSERT

INSERT [ JSON ] INTO [<keyspace_name>.]<table_name>
  [ <column_list> VALUES <column_values> ]
  [ IF NOT EXISTS ]
  [ USING [ TTL <seconds> ] [ [ AND ] TIMESTAMP <epoch_in_microseconds> ] ] ;

LIST PERMISSIONS

LIST ( ALL PERMISSIONS | <permission_list> )
  [ ON <resource_name> ]
  [ OF <role_name> ]
  [ NORECURSIVE ] ;

LIST ROLES

LIST ROLES
  [ OF <role_name> ]
  [ NORECURSIVE ] ;

RESTRICT

RESTRICT <permission>
  ON [<keyspace_name>.]<table_name>
  TO <role_name> ;

RESTRICT ROWS

RESTRICT ROWS
  ON [<keyspace_name>.]<table_name>
  USING <pk_column_name> ;

REVOKE

REVOKE <permission>
  ON <resource_name>
  FROM <role_name> ;

SELECT

SELECT [ JSON ] <selectors>
  FROM [<keyspace_name>.]<table_name>
  [ WHERE [ <primary_key_conditions> | <non_primary_key_conditions> IN (<column_name> &#8230;&#8203;) ALLOW FILTERING ] [ AND ] [ <index_conditions> ]
  [ GROUP BY <column_name> [ , &#8230;&#8203; ] ]
  [ ORDER BY <PK_column_name> [ , &#8230;&#8203; ] ( ASC | DESC ) ] |
  [ ORDER BY <vector_column_name> ANN OF [n,n,n,...] [ LIMIT N ] ]
  [ ( LIMIT <N> | PER PARTITION LIMIT <N> ) ]
  [ ALLOW FILTERING ] ;

TRUNCATE

TRUNCATE [ TABLE ] [<keyspace_name>.]<table_name> ;

UNRESTRICT

UNRESTRICT <permission_name>
  ON [<keyspace_name>.]<table_name>
  FROM <role_name> ;

UNRESTRICT ROWS

UNRESTRICT ROWS ON [<keyspace_name>.]<table_name> ;

UPDATE

UPDATE [<keyspace_name>.]<table_name>
  [ USING TTL <time_value> ]
  [ [ AND ] USING TIMESTAMP <timestamp_value> ]
  SET <assignment> [ , <assignment> ... ]
  WHERE <row_specification>
  [ IF EXISTS | IF <condition> [ AND <condition> ] ] ;

USE

USE <keyspace_name> ;

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