Cypher syntax for administration commands

Almost all administration commands have variations. The most common are parts of the command that are optional or that can have multiple values.

See below a summary of the syntax used to describe all versions of a command. These summaries use some special characters to indicate such variations.

Reading the administration commands syntax

Table 1. Special characters in syntax summaries
Character Meaning Example

|

Used to indicate alternative parts of a command (i.e. or). Needs to be part of a grouping.

If the syntax needs to specify either a name or *, this can be indicated with * | name.

{ and }

Used to group parts of the command. Commonly found together with |.

In order to use the or in the syntax summary, it needs to be in a group: {* | name}.

[ and ]

Used to indicate an optional part of the command. It also groups alternatives together, when there can be either of the alternatives or nothing.

If a keyword in the syntax can either be in singular or plural, we can indicate that the S is optional with GRAPH[S].

...

Repeated pattern. Related to the command part immediately before this is repeated.

A comma separated list of names would be name[, ...].

"

When a special character is part of the syntax itself, we surround it with " to indicate this.

To include { in the syntax use "{" { * | name } "}". In this case, you will get either { * } or { name }.

The special characters in the table above are the only ones that need to be escaped using " in the syntax summaries.

Here is an example that uses all the special characters. It grants the READ privilege:

GRANT READ
  "{" { * | property[, ...] } "}"
  ON {HOME GRAPH | GRAPH[S] { * | name[, ...] }}
    [ ELEMENT[S] { * | label-or-rel-type[, ...] }
    | NODE[S] { * | label[, ...] }
    | RELATIONSHIP[S] { * | rel-type[, ...] }]
  TO role[, ...]

Note that this command includes { and } in the syntax, and between them there can be a grouping of properties or the character *. It also has multiple optional parts, including the entity part of the command which is the grouping following the graph name.

However, there is no need to escape any characters when creating a constraint for a node property. This is because ( and ) are not special characters, and [ and ] indicate that the constraint name and the IF NOT EXISTS parts are optional, and therefore not part of the command.

CREATE CONSTRAINT [constraint_name] [IF NOT EXISTS]
FOR (n:LabelName)
REQUIRE n.propertyName IS NOT NULL

Database management command syntax

The below table covers both standard and composite databases.

Command Syntax

SHOW DATABASE

SHOW { DATABASE[S] name | DATABASE[S] | DEFAULT DATABASE | HOME DATABASE }
[WHERE expression]
SHOW { DATABASE[S] name | DATABASE[S] | DEFAULT DATABASE | HOME DATABASE }
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]

CREATE DATABASE

CREATE DATABASE name [IF NOT EXISTS]
[TOPOLOGY n PRIMAR{Y|IES} [m SECONDAR{Y|IES}]]
[OPTIONS "{" option: value[, ...] "}"]
[WAIT [n [SEC[OND[S]]]]|NOWAIT]
CREATE OR REPLACE DATABASE name
[TOPOLOGY n PRIMAR{Y|IES} [m SECONDAR{Y|IES}]]
[OPTIONS "{" option: value[, ...] "}"]
[WAIT [n [SEC[OND[S]]]]|NOWAIT]

CREATE COMPOSITE DATABASE

CREATE COMPOSITE DATABASE name [IF NOT EXISTS]
[OPTIONS "{" "}"]
[WAIT [n [SEC[OND[S]]]]|NOWAIT]
CREATE OR REPLACE COMPOSITE DATABASE name
[OPTIONS "{" "}"]
[WAIT [n [SEC[OND[S]]]]|NOWAIT]

ALTER DATABASE

ALTER DATABASE name [IF EXISTS]
{
SET ACCESS {READ ONLY | READ WRITE} |
SET TOPOLOGY n PRIMAR{Y|IES} [m SECONDAR{Y|IES}] |
SET OPTION option value
}
[WAIT [n [SEC[OND[S]]]]|NOWAIT]
ALTER DATABASE name [IF EXISTS]
REMOVE OPTION option
[WAIT [n [SEC[OND[S]]]]|NOWAIT]

There can be multiple SET OPTION or REMOVE OPTION clauses for different option keys.

STOP DATABASE

STOP DATABASE name [WAIT [n [SEC[OND[S]]]]|NOWAIT]

START DATABASE

START DATABASE name [WAIT [n [SEC[OND[S]]]]|NOWAIT]

DROP DATABASE

DROP [COMPOSITE] DATABASE name [IF EXISTS] [{DUMP|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]|NOWAIT]

Database alias management command syntax

Command Syntax

Show Database Alias

SHOW ALIAS[ES] [name] FOR DATABASE[S]
[WHERE expression]
SHOW ALIAS[ES] [name] FOR DATABASE[S]
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]

Lists both local and remote database aliases, optionally filtered on the alias name.

Create Local Alias

CREATE ALIAS name [IF NOT EXISTS] FOR DATABASE targetName
[PROPERTIES "{" key: value[, ...] "}"]
CREATE OR REPLACE ALIAS name FOR DATABASE targetName
[PROPERTIES "{" key: value[, ...] "}"]

Create Remote Alias

CREATE ALIAS name [IF NOT EXISTS] FOR DATABASE targetName
AT 'url' USER username PASSWORD 'password'
[DRIVER "{" setting: value[, ...] "}"]
[PROPERTIES "{" key: value[, ...] "}"]
CREATE OR REPLACE ALIAS name FOR DATABASE targetName
AT 'url' USER username PASSWORD 'password'
[DRIVER "{" setting: value[, ...] "}"]
[PROPERTIES "{" key: value[, ...] "}"]

Alter Local Alias

ALTER ALIAS name [IF EXISTS] SET DATABASE
[TARGET targetName]
[PROPERTIES "{" key: value[, ...] "}"]

Alter Remote Alias

ALTER ALIAS name [IF EXISTS] SET DATABASE
[TARGET targetName AT 'url']
[USER username]
[PASSWORD 'password']
[DRIVER "{" setting: value[, ...] "}"]
[PROPERTIES "{" key: value[, ...] "}"]

Drop Alias

DROP ALIAS name [IF EXISTS] FOR DATABASE

Drop either a local or remote database alias.