CREATE multiple constraints at once

How can I create multiple constraints at once?

When I try

CREATE CONSTRAINT uniqueAppId IF NOT EXISTS
FOR (n:User)
REQUIRE n.appId IS UNIQUE

CREATE CONSTRAINT uniqueIpAddress IF NOT EXISTS
FOR (n:IpAddress)
REQUIRE n.ip IS UNIQUE

I get the error:

Neo.ClientError.Statement.SyntaxError
Invalid input 'CREATE': expected "OPTIONS" or <EOF> (line 5, column 1 (offset: 84))
"CREATE CONSTRAINT uniqueIpAddress IF NOT EXISTS"
 ^

But these work fine if I query them separately.

  • neo4j version: 5

Try ending each statement with a semicolon.

3 Likes

At least in Neo4j Browser / Query and cypher-shell that's how it works.

With a driver you'll have to send them individually.

1 Like