CQL quick reference
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 [CUSTOM] INDEX [ IF NOT EXISTS ] [ <index_name> ]
ON [<keyspace_name>.]<table_name>
([ KEYS | VALUES | ENTRIES | FULL] <column_name>)
USING <index_type>
[ WITH OPTIONS = { <option_map> } ] ;
CREATE TABLE
CREATE TABLE [ IF NOT EXISTS ] [<keyspace_name>.]<table_name>
( <column_definition> [ , ... ] | [ PRIMARY KEY (partition_key_column_name, clustering_column_name) ] )
[ WITH COMPACT STORAGE ] (1)
[ AND <table_options> ]
[ CLUSTERING ORDER BY [ <clustering_column_name> [ ASC | DESC ] ][ , ... ] ] (2)
ifdef::dse68[]
[ AND ( VERTEX LABEL <vl_name> | EDGE LABEL ) <el_name> FROM <vl_name> TO <vl_name>]
endif::dse68[]
[ [ AND ] ID = '<table_hash_tag>' ] ] ; (3)
1 | ONLY SUPPORTED FOR DSE 5.1 OR EARLER. Use only to migrate to a later DSE version. |
2 | The CLUSTERING ORDER BY clause is optional.
If not specified, the default is ASC . |
3 | The ID clause is optional.
If specified, the table is created with a hash tag that is used to identify the table in the schema.
If a table is accidentally dropped, use this option to recreate the table and run a commit log replay to retrieve the data. |
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 ROLE
GRANT <role_name> TO <role_name> ;
GRANT PERMISSION
GRANT <permission> ON <resource> 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 ROLE
REVOKE <role_name> FROM <role_name> ;
REVOKE PERMISSION
REVOKE <permission> ON <resource_name> FROM <role_name> ;
SELECT
SELECT [ JSON | DISTINCT ] <selectors>
FROM [<keyspace_name>.]<table_name>
[ WHERE [ <primary_key_conditions> | <non_primary_key_conditions> IN (<column_name> [, ...]) ALLOW FILTERING ] [ AND ] [ <index_conditions> ]
[ GROUP BY <column_name> [ , ... ] ]
[ ORDER BY <column_name> ( ASC | DESC ) [ , ... ] ] |
[ ORDER BY <vector_column_name> ANN OF [n,n,n,...] [ LIMIT N ] ]
[ ( LIMIT <N> [ OFFSET <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> ;