How do I get the already existing constraints in Neo4j?
Asked Answered
C

6

6

When I've created some constraints on the graph, how is possible to see them and in case eliminate them? What is the syntax to treat them as elements of the graph?

Corell answered 9/2, 2014 at 11:7 Comment(0)
L
7

In the neo4j browser you can use the :schema command to list them. In shell it is schema

Then you can remove them with

`DROP INDEX ON :Label(prop)` 

or

`DROP CONSTRAINT ON (n:Label) ASSERT n.props IS UNIQUE`
Lynnette answered 9/2, 2014 at 11:28 Comment(0)
F
7

In Browser you can use CALL db.constraints to get all constraints on graph.

For more Info: https://neo4j.com/docs/developer-manual/current/cypher/schema/constraints/

Frontispiece answered 30/8, 2018 at 15:39 Comment(2)
Welcome to SO! Thanks for the reply, but this topic is 4 years old ;)Corell
You can also use this command programmatically - just tested in the neo4j python driver which is 'officially supported' - assuming that means it is a standard driver feature. 4 years old questions need love too ;)Equatorial
A
7

to do this in cypher you can execute

CALL db.constraints;

which gives a table of constraints from which you can delete entries by referencing the name column when executing

DROP CONSTRAINT constraint_name;
Apply answered 23/2, 2021 at 14:6 Comment(0)
M
6

In Neo4j 5.x.x, its SHOW CONSTRAINT command.

Maronite answered 2/10, 2023 at 20:19 Comment(0)
P
2

SHOW CONSTRAINTS

I was able to get existing constraints with the above using the neo4j:5-community Docker image.

Peroxide answered 17/8, 2023 at 19:44 Comment(0)
A
1

Running

call db.schemaStatements()

seems to give the constraints along with the syntax of the DROP statement as well, ready to copy/paste, for example:

DROP CONSTRAINT `publisher_id`
Albatross answered 11/1, 2021 at 18:21 Comment(1)
Note that I'm running 4.1.5 Community, which is rather newer than the OP's version! I'm answering here because this information would have been useful to me when I found this answer.Albatross

© 2022 - 2024 — McMap. All rights reserved.