Create, show, and drop constraints

This page describes how to create, list, and drop constraints. The following constraint types are available in Neo4j:

CREATE CONSTRAINT

Constraints are created with the CREATE CONSTRAINT command. When creating a constraint, it is recommended to provide a constraint name. This name must be unique among both indexes and constraints. If a name is not explicitly given, a unique name will be auto-generated.

Creating a constraint requires the CREATE CONSTRAINT privilege.
Adding constraints is an atomic operation that can take a while — all existing data has to be scanned before a Neo4j DBMS can use a constraint.

Create property uniqueness constraints

Property uniqueness constraints ensure that the property values are unique for all nodes with a specific label or all relationships with a specific type. For composite property uniqueness constraints on multiple properties, it is the combination of property values that must be unique. Queries that try to add duplicated property values will fail.

Property uniqueness constraints do not require all nodes or relationships to have values for the properties listed in the constraint. Only nodes or relationships that contain all properties specified in the constraint are subject to the uniqueness rule. Nodes or relationships missing one or more of the specified properties are not subject to this rule.

Create a single property uniqueness constraint

Single property uniqueness constraints are created with the following commands:

  • Node property uniqueness constraints: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE n.property IS UNIQUE.

  • Relationship property uniqueness constraints: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS UNIQUE. Introduced in 5.7

For the full command syntax to create a property uniqueness constraint, see Syntax → Create property uniqueness constraints.

Example 1. Create a node property uniqueness constraint on a single property
Create a constraint requiring Book nodes to have unique isbn properties
CREATE CONSTRAINT book_isbn
FOR (book:Book) REQUIRE book.isbn IS UNIQUE
Result
Added 1 constraint.
The detailed statistics view currently says Unique constraints added: 1. It will be updated to say Node property uniqueness constraints added: 1 in a future version of Neo4j.
Example 2. Create a relationship property uniqueness constraint on a single property Introduced in 5.7
Create a constraint requiring SEQUEL_OF relationships to have unique order properties
CREATE CONSTRAINT sequels
FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE
Result
Added 1 constraint.
The detailed statistics view currently says Relationship uniqueness constraints added: 1. It will be updated to say Relationship property uniqueness constraints added: 1 in a future version of Neo4j.

Create a composite property uniqueness constraint

Constraints created for multiple properties are called composite constraints. Note that the constrained properties must be parenthesized when creating composite property uniqueness constraints.

  • Node property uniqueness constraints: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE (n.propertyName_1, …​, n.propertyName_n) IS UNIQUE.

  • Relationship property uniqueness constraints: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE (r.propertyName_1, …​, r.propertyName_n) IS UNIQUE. Introduced in 5.7

For the full command syntax to create a property uniqueness constraint, see Syntax → Create property uniqueness constraints.

Example 3. Create a composite node property uniqueness constraint on several properties
Create a constraint requiring Book nodes to have unique combinations of title and publicationYear properties
CREATE CONSTRAINT book_title_year
FOR (book:Book) REQUIRE (book.title, book.publicationYear) IS UNIQUE
Result
Added 1 constraint.
Example 4. Create a composite relationship property uniqueness constraint on several properties Introduced in 5.7
Create a constraint requiring PREQUEL_OF relationships to have unique combinations of order and author properties
CREATE CONSTRAINT prequels
FOR ()-[prequel:PREQUEL_OF]-() REQUIRE (prequel.order, prequel.author) IS UNIQUE
Result
Added 1 constraint.

Create data that complies with existing property uniqueness constraints

Example 5. Create a node that complies with existing property uniqueness constraints
Create a Book node with a unique isbn property
CREATE (book:Book {isbn: '1449356265', title: 'Graph Databases'})
Result
Added 1 label, created 1 node, set 2 properties
Example 6. Create a relationship that complies with existing property uniqueness constraints
Create a SEQUEL_OF relationship with a unique order property
CREATE (:Book {title: 'Spirit Walker'})-[:SEQUEL_OF {order: 1, seriesTitle: 'Chronicles of Ancient Darkness'}]->(:Book {title: 'Wolf Brother'})
Result
Added 2 labels, created 2 nodes, set 4 properties, created 1 relationship.

Create property existence constraints

Property existence constraints ensure that a property exists either for all nodes with a specific label or for all relationships with a specific type. Queries that try to create new nodes of the specified label, or relationships of the specified type, without the constrained property will fail. The same is true for queries that try to remove the mandatory property.

Create a single property existence constraint

Property existence constraints on single properties are created with the following commands:

  • Node property existence constraint: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE n.property IS NOT NULL.

  • Relationship property existence constraint: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS NOT NULL.

For the full command syntax to create an existence constraint, see Syntax → Create property existence constraints.

It is not possible to create composite existence constraints on several properties.
Example 7. Create a node property existence constraint
Create a constraint requiring Author nodes to have a name property
CREATE CONSTRAINT author_name
FOR (author:Author) REQUIRE author.name IS NOT NULL
Result
Added 1 constraint.
Example 8. Create a relationship property existence constraint
Create a constraint requiring WROTE relationships to have a year property
CREATE CONSTRAINT wrote_year
FOR ()-[wrote:WROTE]-() REQUIRE wrote.year IS NOT NULL
Result
Added 1 constraint.

Create data that complies with existing property existence constraints

Example 9. Create a node that complies with existing node property existence constraints
Create an Author node with a name property:
CREATE (author:Author {name:'Virginia Woolf', surname: 'Woolf'})
Result
Added 1 label, created 1 node, set 2 properties
Example 10. Create a relationship that complies with existing relationship property existence constraints
Create a WROTE relationship with a year property
CREATE (author:Author {name: 'Emily Brontë', surname: 'Brontë'})-[wrote:WROTE {year: 1847, location: 'Haworth, United Kingdom', published: true}]->(book:Book {title:'Wuthering Heights', isbn: 9789186579296})
Result
Added 2 labels, created 2 nodes, set 7 properties, created 1 relationship

Create property type constraints

Property type constraints ensure that a property has the required data type for all nodes with a specific label or for all relationships with a specific type. Queries that attempt to add this property with the wrong data type or modify this property in a way that changes its data type for nodes of the specified label or relationships of the specified type will fail.

Property type constraints do not require all nodes or relationships to have the property. Nodes or relationships without the constrained property are not subject to this rule.

Create a single property type constraint

Property type constraints are created with the following commands:

  • Node property type constraints: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE n.property IS :: <TYPE>.

  • Relationship property type constraints: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS :: <TYPE>.

<TYPE> refers to a specific Cypher® data type, such as STRING or INTEGER. For the types that properties can be constrained by, see Allowed types, and for information about different data types in Cypher, see Values and types. For the full command syntax to create a property type constraint, see Syntax → Create property type constraints.

It is not possible to create composite property type constraints on several properties.
Example 11. Create a node property type constraint
Create a constraint requiring title properties on Movie nodes to be of type STRING
CREATE CONSTRAINT movie_title
FOR (movie:Movie) REQUIRE movie.title IS :: STRING
Result
Added 1 constraint.
Example 12. Create a relationship property type constraint
Create a constraint requiring order properties on PART_OF relationships to be of type INTEGER
CREATE CONSTRAINT part_of
FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: INTEGER
Result
Added 1 constraint.

Create property type constraints with a union type

A closed dynamic union allows a node or relationship property to maintain some type flexibility whilst preventing unexpected values from being stored.

Example 13. Create a node property type constraint with a union type
Create a constraint requiring tagline properties on Movie nodes to be either of type STRING or LIST<STRING NOT NULL>
CREATE CONSTRAINT movie_tagline
FOR (movie:Movie) REQUIRE movie.tagline IS :: STRING | LIST<STRING NOT NULL>
Result
Added 1 constraint.
Example 14. Create a relationship property type constraint with a union type
Create a constraint requiring tags properties on PART_OF relationships to either of type STRING or LIST<STRING NOT NULL>
CREATE CONSTRAINT part_of_tags
FOR ()-[part:PART_OF]-() REQUIRE part.tags IS :: STRING | LIST<STRING NOT NULL>
Result
Added 1 constraint.

Allowed types

The allowed property types for property type constraints are:

  • BOOLEAN

  • STRING

  • INTEGER

  • FLOAT

  • DATE

  • LOCAL TIME

  • ZONED TIME

  • LOCAL DATETIME

  • ZONED DATETIME

  • DURATION

  • POINT

  • LIST<BOOLEAN NOT NULL> Introduced in 5.10

  • LIST<STRING NOT NULL> Introduced in 5.10

  • LIST<INTEGER NOT NULL> Introduced in 5.10

  • LIST<FLOAT NOT NULL> Introduced in 5.10

  • LIST<DATE NOT NULL> Introduced in 5.10

  • LIST<LOCAL TIME NOT NULL> Introduced in 5.10

  • LIST<ZONED TIME NOT NULL> Introduced in 5.10

  • LIST<LOCAL DATETIME NOT NULL> Introduced in 5.10

  • LIST<ZONED DATETIME NOT NULL> Introduced in 5.10

  • LIST<DURATION NOT NULL> Introduced in 5.10

  • LIST<POINT NOT NULL> Introduced in 5.10

  • Any closed dynamic union of the above types, e.g. INTEGER | FLOAT | STRING. Introduced in 5.11

For a complete reference describing all types available in Cypher, see the section on types and their synonyms.

Creating property type constraints on invalid types will fail

Example 15. Create a node property type constraint with an invalid type
Create a constraint requiring imdbScore properties on Movie nodes to be of type MAP
CREATE CONSTRAINT score FOR (movie:Movie) REQUIRE movie.imdbScore IS :: MAP
Error message
Failed to create node property type constraint: Invalid property type `MAP`.

Create data that complies with existing property type constraints

Example 16. Create a node that complies with existing node property type constraint
Create an Movie node with a STRING title property
CREATE (movie:Movie {title:'Iron Man'})
Result
Added 1 label, created 1 node, set 1 properties
Example 17. Create a relationship that complies with existing relationship property type constraint
Create a PART_OF relationship with an INTEGER order property
MATCH (movie:Movie {title:'Iron Man'})
CREATE (movie)-[part:PART_OF {order: 3}]->(franchise:Franchise {name:'MCU'})
Result
Added 1 label, added 1 node, created 1 relationship, set 2 properties

Create key constraints

Key constraints ensure that the property exist and the property value is unique for all nodes with a specific label or all relationships with a specific type. For composite key constraints on multiple properties, all properties must exists and the combination of property values must be unique.

Queries that try to create new nodes of the specified label, or relationships of the specified type, without the constrained property will fail. The same is true for queries that try to remove the mandatory property or add duplicated property values.

Create a single property key constraint

Single property key constraints are created with the following commands:

  • Node key constraints: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE n.property IS NODE KEY.

  • Relationship key constraints: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS RELATIONSHIP KEY. Introduced in 5.7

For the full command syntax to create a key constraint, see Syntax → Create key constraints.

Example 18. Create a node key constraint on a single property
Create a constraint requiring Director nodes to have a unique imdbId property as a node key.
CREATE CONSTRAINT director_imdbId
FOR (director:Director) REQUIRE (director.imdbId) IS NODE KEY
Result
Added 1 constraint.
Example 19. Create a relationship key constraint on a single property Introduced in 5.7
Create a constraint requiring OWNS relationships to have a unique ownershipId property as a relationship key
CREATE CONSTRAINT ownershipId
FOR ()-[owns:OWNS]-() REQUIRE owns.ownershipId IS RELATIONSHIP KEY
Result
Added 1 constraint.

Create a composite key constraint

Constraints created for multiple properties are called composite constraints. Note that the constrained properties must be parenthesized when creating composite key constraints.

Composite key constraints are created with the following commands:

  • Node key constraints: CREATE CONSTRAINT constraint_name FOR (n:Label) REQUIRE (n.propertyName_1, …​, n.propertyName_n) IS NODE KEY.

  • Relationship key constraints: CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE (r.propertyName_1, …​, r.propertyName_n) IS RELATIONSHIP KEY. Introduced in 5.7

For the full command syntax to create a key constraint, see Syntax → Create key constraints.

Example 20. Create a composite node key constraint on multiple properties
Create a constraint requiring Actor nodes to have a unique combination of firstname and surname properties as a node key
CREATE CONSTRAINT actor_fullname
FOR (actor:Actor) REQUIRE (actor.firstname, actor.surname) IS NODE KEY
Result
Added 1 constraint.
Example 21. Create a composite relationship key constraint label on multiple properties Introduced in 5.7
Create a constraint requiring KNOWS relationships to have a unique combination of since and how properties as a relationship key
CREATE CONSTRAINT knows_since_how
FOR ()-[knows:KNOWS]-() REQUIRE (knows.since, knows.how) IS RELATIONSHIP KEY
Result
Added 1 constraint.

Create data that complies with existing key constraints

Example 22. Create a node that complies with existing node key constraints
Create an Actor node with unique firstname and surname properties
CREATE (actor:Actor {firstname: 'Keanu', surname: 'Reeves'})
Result
Added 1 label, created 1 node, set 2 properties.
Example 23. Create a relationship that complies with existing relationship key constraints
Create a KNOWS relationship with unique since and how properties
CREATE (:Actor {firstname: 'Jensen', surname: 'Ackles'})-[:KNOWS {since: 2008, how: 'coworkers', friend: true}]->(:Actor {firstname: 'Misha', surname: 'Collins'})
Result
Added 2 labels, created 2 nodes, set 7 properties, created 1 relationship.

Create a constraint with a parameter

All constraint types can be created with a parameterized name.

Example 24. Create a node property uniqueness constraint using a parameter
Parameters
{
  "name": "node_uniqueness_param"
}
Create a node property uniqueness constraint with a parameterized name
CREATE CONSTRAINT $name
FOR (book:Book) REQUIRE book.prop1 IS UNIQUE
Result
Added 1 constraint.
Example 25. Create a relationship property existence constraint using a parameter
Parameters
{
  "name": "rel_exist_param"
}
Create a relationship property existence constraint with a parameterized name
CREATE CONSTRAINT $name
FOR ()-[wrote:WROTE]-() REQUIRE wrote.published IS NOT NULL
Result
Added 1 constraint.

Handling multiple constraints

Creating an already existing constraint will fail. This includes the following scenarios:

  • Creating a constraint identical to an already existing constraint.

  • Creating a constraint with a different name but on the same constraint type and same label/relationship type and property combination as an already existing constraint. For property type constraints the property type also needs to be the same.

  • Creating a constraint with the same name as an already existing constraint, regardless of what that constraint is.

Additionally, some constraints cannot coexist and attempting to create them together will therefore fail as well. This includes:

  • Property type constraints on the same label/relationship type and property but with different property types.

  • Property uniqueness and key constraints on the same label/relationship type and property combination.

However, some constraint types are allowed on the same label/relationship type and property combination. For example, it is possible to have a property uniqueness and a property existence constraint on the same label/relationship type and property combination, though this would be the equivalent of having a node or relationship key constraint. A more useful example would be to combine a property type and a property existence constraint to ensure that the property exists and has the given type.

Handling existing constraints when creating a constraint

To avoid failing on existing constraints, IF NOT EXISTS can be added to the CREATE command. This will ensure that no error is thrown and that no constraint is created if any other constraint with the given name, or another constraint on the same constraint type and schema, or both, already exists. For property type constraints the property type also needs to be the same. As of Neo4j 5.17, an informational notification is instead returned showing the existing constraint which blocks the creation.

Example 26. Create a constraint identical to an existing constraint
Create a constraint requiring all SEQUEL_OF relationships to have unique order properties
CREATE CONSTRAINT sequels IF NOT EXISTS
FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE

Because the same constraint already exists, nothing will happen:

Result
(no changes, no records)
Notification
`CREATE CONSTRAINT sequels IF NOT EXISTS FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` has no effect.
`CONSTRAINT sequels FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` already exists.
Example 27. Create a relationship property uniqueness constraint when the same constraint with a different name already exists
Create a constraint requiring all SEQUEL_OF relationships to have unique order properties
CREATE CONSTRAINT new_sequels IF NOT EXISTS
FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE

Because a constraint with a different name (sequels) on the same schema exists, nothing will happen:

Result
(no changes, no records)
Notification
`CREATE CONSTRAINT new_sequels IF NOT EXISTS FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` has no effect.
`CONSTRAINT sequels FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` already exists.
Example 28. Create a relationship property uniqueness constraint with the same name as an existing constraint of a different type
Create a constraint requiring all AUTHORED relationships to have unique name properties
CREATE CONSTRAINT author_name IF NOT EXISTS
FOR ()-[a:AUTHORED]-() REQUIRE a.name IS UNIQUE

Because a node property existence constraint named author_name already exists, nothing will happen:

Result
(no changes, no records)
Notification
`CREATE CONSTRAINT author_name IF NOT EXISTS FOR ()-[e:AUTHORED]-() REQUIRE (e.name) IS UNIQUE` has no effect.
`CONSTRAINT author_name FOR (e:Author) REQUIRE (e.name) IS NOT NULL` already exists.

Creating an already existing constraint will fail

Creating a constraint with the same name or on the same node label or relationship type and properties that are already constrained by a constraint of the same type will fail. Property uniqueness and key constraints are also not allowed on the same schema.

Example 29. Create a constraint identical to an existing constraint
Create a constraint requiring all SEQUEL_OF relationships to have unique order properties, given an identical constraint already exists
CREATE CONSTRAINT sequels
FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE
Error message
An equivalent constraint already exists, 'Constraint( id=5, name='sequels', type='RELATIONSHIP UNIQUENESS', schema=()-[:SEQUEL_OF {order}]-(), ownedIndex=4 )'.
The constraint type will be updated to say RELATIONSHIP PROPERTY UNIQUENESS in a future version of Neo4j.
Example 30. Create a constraint with a different name but on the same schema as an existing constraint
Create a constraint requiring all Book nodes to have unique isbn properties, given that a constraint on that schema already exists
CREATE CONSTRAINT new_book_isbn
FOR (book:Book) REQUIRE book.isbn IS UNIQUE
Error message
Constraint already exists: Constraint( id=3, name='book_isbn', type='UNIQUENESS', schema=(:Book {isbn}), ownedIndex=2 )
The constraint type will be updated to say NODE PROPERTY UNIQUENESS in a future version of Neo4j.
Example 31. Creating a constraint with the same name but on a different schema as an existing constraint
Create a constraint requiring all AUTHORED relationships to have unique name properties, given that a constraint on a different schema with the same name already exists
CREATE CONSTRAINT author_name
FOR ()-[a:AUTHORED]-() REQUIRE a.name IS UNIQUE
Error message
There already exists a constraint called 'author_name'.
Example 32. Creating a property type constraint on a property when a property type constraint constraining the property to a different type already exist
Create a constraint requiring order properties on PART_OF relationships to be of type FLOAT, given a constraint requiring the same properties to be of type INTEGER already exists
CREATE CONSTRAINT new_part_of
FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: FLOAT
Error message
Conflicting constraint already exists: Constraint( id=21, name='part_of', type='RELATIONSHIP PROPERTY TYPE', schema=()-[:PART_OF {order}]-(), propertyType=INTEGER )
Example 33. Creating a node key constraint on the same schema as an existing property uniqueness constraint
Create a node key constraint on the properties title and publicationYear on nodes with the Book label, when a property uniqueness constraint already exists on the same label and property combination
CREATE CONSTRAINT book_titles FOR (book:Book) REQUIRE (book.title, book.publicationYear) IS NODE KEY
Error message
Constraint already exists: Constraint( id=7, name='book_title_year', type='UNIQUENESS', schema=(:Book {title, publicationYear}), ownedIndex=6 )

Constraints and indexes

Constraints and backing indexes

Property uniqueness constraints and key constraints are backed by range indexes. This means that creating a property uniqueness or key constraint will create a range index with the same name, node label/relationship type and property combination as its owning constraint. Single property constraints will create single property indexes and multiple property composite constraints will create composite indexes.

Indexes of the same index type, label/relationship type, and property combination cannot be added separately. However, dropping a property uniqueness or key constraint will also drop its backing index. If the backing index is still required, the index needs to be explicitly re-created.

Property uniqueness and key constraints require an index because it allows the system to quickly check if a node with the same label and property value or a relationship with the same type and property value already exists. Without an index, the system would need to scan all nodes with the same label, which would be slow and inefficient, especially as the graph grows. The index makes these checks much faster by enabling direct lookups instead of scanning the entire graph. Cypher will use the indexes with an owning constraint in the same way that it utilizes other search-performance indexes. For more information about how indexes impact query performance, see The impact of indexes on query performance.

These indexes are listed in the owningConstraint column returned by the SHOW INDEX command, and the ownedIndex column returned by the SHOW CONSTRAINT command.

Example 34. List constraints with backing indexes
Query
SHOW CONSTRAINTS WHERE ownedIndex IS NOT NULL
Result
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                    | type                      | entityType     | labelsOrTypes  | properties                   | ownedIndex              | propertyType |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 21 | "actor_fullname"        | "NODE_KEY"                | "NODE"         | ["Actor"]      | ["firstname", "surname"]     | "actor_fullname"        | NULL         |
| 3  | "book_isbn"             | "UNIQUENESS"              | "NODE"         | ["Book"]       | ["isbn"]                     | "book_isbn"             | NULL         |
| 7  | "book_title_year"       | "UNIQUENESS"              | "NODE"         | ["Book"]       | ["title", "publicationYear"] | "book_title_year"       | NULL         |
| 17 | "director_imdbId"       | "NODE_KEY"                | "NODE"         | ["Director"]   | ["imdbId"]                   | "director_imdbId"       | NULL         |
| 23 | "knows_since_how"       | "RELATIONSHIP_KEY"        | "RELATIONSHIP" | ["KNOWS"]      | ["since", "how"]             | "knows_since_how"       | NULL         |
| 25 | "node_uniqueness_param" | "UNIQUENESS"              | "NODE"         | ["Book"]       | ["prop1"]                    | "node_uniqueness_param" | NULL         |
| 19 | "ownershipId"           | "RELATIONSHIP_KEY"        | "RELATIONSHIP" | ["OWNS"]       | ["ownershipId"]              | "ownershipId"           | NULL         |
| 9  | "prequels"              | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"]          | "prequels"              | NULL         |
| 5  | "sequels"               | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"]  | ["order"]                    | "sequels"               | NULL         |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Example 35. List indexes with owning constraints
Query
SHOW INDEXES WHERE owningConstraint IS NOT NULL
Result
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                    | state    | populationPercent | type    | entityType     | labelsOrTypes  | properties                   | indexProvider | owningConstraint        | lastRead                 | readCount |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 20 | "actor_fullname"        | "ONLINE" | 100.0             | "RANGE" | "NODE"         | ["Actor"]      | ["firstname", "surname"]     | "range-1.0"   | "actor_fullname"        | 2024-10-07T12:12:51.893Z | 3         |
| 2  | "book_isbn"             | "ONLINE" | 100.0             | "RANGE" | "NODE"         | ["Book"]       | ["isbn"]                     | "range-1.0"   | "book_isbn"             | 2024-10-07T11:58:09.252Z | 2         |
| 6  | "book_title_year"       | "ONLINE" | 100.0             | "RANGE" | "NODE"         | ["Book"]       | ["title", "publicationYear"] | "range-1.0"   | "book_title_year"       | NULL                     | 0         |
| 16 | "director_imdbId"       | "ONLINE" | 100.0             | "RANGE" | "NODE"         | ["Director"]   | ["imdbId"]                   | "range-1.0"   | "director_imdbId"       | NULL                     | 0         |
| 22 | "knows_since_how"       | "ONLINE" | 100.0             | "RANGE" | "RELATIONSHIP" | ["KNOWS"]      | ["since", "how"]             | "range-1.0"   | "knows_since_how"       | 2024-10-07T12:12:51.894Z | 1         |
| 24 | "node_uniqueness_param" | "ONLINE" | 100.0             | "RANGE" | "NODE"         | ["Book"]       | ["prop1"]                    | "range-1.0"   | "node_uniqueness_param" | NULL                     | 0         |
| 18 | "ownershipId"           | "ONLINE" | 100.0             | "RANGE" | "RELATIONSHIP" | ["OWNS"]       | ["ownershipId"]              | "range-1.0"   | "ownershipId"           | NULL                     | 0         |
| 8  | "prequels"              | "ONLINE" | 100.0             | "RANGE" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"]          | "range-1.0"   | "prequels"              | NULL                     | 0         |
| 4  | "sequels"               | "ONLINE" | 100.0             | "RANGE" | "RELATIONSHIP" | ["SEQUEL_OF"]  | ["order"]                    | "range-1.0"   | "sequels"               | 2024-10-07T11:57:12.999Z | 1         |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Property existence and property type constraints are not backed by indexes.

Constraint failures and indexes

Attempting to create any type of constraint with the same name as an existing index will fail.

Example 36. Creating a node property type constraint with the same name as an existing index
Create an index with the name directors
CREATE INDEX directors FOR (director:Director) ON (director.name)
Create a node property type constraint with the name directors
CREATE CONSTRAINT directors FOR (movie:Movie) REQUIRE movie.director IS :: STRING
Error message
There already exists an index called 'directors'.

Creating key or property uniqueness constraints on the same schema as an existing index will fail.

Example 37. Creating a node property uniqueness constraint on the same schema as an existing index
Create an index for wordCount properties on Book nodes
CREATE INDEX book_word_count FOR (book:Book) ON (book.wordCount)
Create a constraint requiring all Book nodes to have unique wordCount properties
CREATE CONSTRAINT word_count FOR (book:Book) REQUIRE book.wordCount IS UNIQUE
Error message
There already exists an index (:Book {wordCount}).
A constraint cannot be created until the index has been dropped.

Constraints and data violation scenarios

Creating data that violates existing constraints will fail

Table 1. Existing constraints preventing data creation
Constraint type Create nodes and relationships without an existence constrained property Create nodes and relationships with non-unique properties/property combinations Create nodes and relationships with the wrong property type

Property uniqueness constraint

Property existence constraint

Property type constraint

Key constraint

Example 38. Create a node that violates a node property uniqueness constraint
Create a Book node with an isbn property that already exists
CREATE (book:Book {isbn: '1449356265', title: 'Graph Databases'})
Error message
Node(0) already exists with label `Book` and property `isbn` = '1449356265'
Example 39. Create a node that violates an existing node property existence constraint
Create an Author node without a name property, given a property existence constraint on :Author(name)
CREATE (author:Author {surname: 'Austen'})
Error message
Node(0) with label `Author` must have the property `name`
Example 40. Create a relationship that violates an existing relationship property type constraint
Create a PART_OF relationship with a STRING order property, given a property type constraint on the relationship type PART_OF restricting the order property to INTEGER values
MATCH (movie:Movie {title:'Iron Man'}), (franchise:Franchise {name:'MCU'})
CREATE (movie)-[part:PART_OF {order: '1'}]->(franchise)
Error message
Relationship(0) with type `PART_OF` has property `order` of wrong type `String`. Allowed types: INTEGER
Example 41. Create a node that violates an existing node key constraint
Create an Actor node without a firstname property, given a node key constraint on :Actor(firstname, surname)
CREATE (actor:Actor {surname: 'Wood'})
Error message
Node(0) with label `Actor` must have the properties (`firstname`, `surname`)

Removing existence and key constrained properties will fail

Example 42. Remove a node property existence constrained property
Remove the name property from an existing Author node, given a property existence constraint on :Author(name)
MATCH (author:Author {name: 'Virginia Woolf'})
REMOVE author.name
Error message
Node(0) with label `Author` must have the property `name`
Example 43. Remove a node key constrained property
Remove the firstname property from an existing node Actor, given a node key constraint on :Actor(firstname, surname)
MATCH (actor:Actor {firstname: 'Keanu', surname: 'Reeves'})
REMOVE actor.firstname
Error message
Node(0) with label `Actor` must have the properties (`firstname`, `surname`)

Modifying type constrained properties will fail

Example 44. Modify a type constrained property
Modify the title for the Movie 'Iron Man' to an INTEGER value, given a constraint requiring title properties to be of type STRING
MATCH (m:Movie {title: 'Iron Man'})
SET m.title = 13
Error message
Node(9) with label `Movie` required the property `title` to be of type `STRING`, but was of type `INTEGER`.

Creating constraints when there exists conflicting data will fail

Table 2. Existing data preventing constraint creation
Constraint type Non-existing property Non-unique property/property combination Property of wrong type

Property uniqueness constraint

Property existence constraint

Property type constraint

Key constraint

Example 45. Create a node property uniqueness constraint when conflicting nodes exist
Create two Book nodes with the same name property value
CREATE (:Book {isbn: '9780393972832', title: 'Moby Dick'}),
       (:Book {isbn: '9780763630188', title: 'Moby Dick'})
Create a constraint requiring Book nodes to have unique title properties, when there already exists two Book nodes with the same title
CREATE CONSTRAINT book_title FOR (book:Book) REQUIRE book.title IS UNIQUE

In this case, the constraint cannot be created because it is in conflict with the existing graph. Either use indexes instead, or remove/correct the offending nodes and then re-apply the constraint.

Error message
Unable to create Constraint( name='book_title', type='UNIQUENESS', schema=(:Book {title}) ):
Both Node(0) and Node(1) have the label `Book` and property `title` = 'Moby Dick'

The constraint creation fails on the first offending nodes that are found. This does not guarantee that there are no other offending nodes in the graph. Therefore, all the data should be checked and cleaned up before re-attempting the constraint creation.

Find all offending nodes with the non-unique property values for the constraint above
MATCH (book1:Book), (book2:Book)
WHERE book1.title = book2.title AND NOT book1 = book2
RETURN book1, book2
Example 46. Create a relationship property existence constraint when conflicting relationships exist
Create a constraint requiring all WROTE relationships to have a language property, when there already exists a WROTE relationship without a language property
CREATE CONSTRAINT wrote_language FOR ()-[wrote:WROTE]-() REQUIRE wrote.language IS NOT NULL

In this case, the constraint cannot be created because it is in conflict with the existing graph. Remove or correct the offending relationships and then re-apply the constraint.

Error message
Unable to create Constraint( type='RELATIONSHIP PROPERTY EXISTENCE', schema=()-[:WROTE {language}]-() ):
Relationship(0) with type `WROTE` must have the property `language`. Note that only the first found violation is shown.

The constraint creation fails on the first offending relationship that is found. This does not guarantee that there are no other offending relationships in the graph. Therefore, all the data should be checked and cleaned up before re-attempting the constraint creation.

Find all offending relationships missing the property for the constraint above
MATCH ()-[wrote:WROTE]-()
WHERE wrote.language IS NULL
RETURN wrote
Table 3. Generic MATCH queries to find the properties preventing the creation of particular constraints:
Constraint Query

Node property uniqueness constraint

MATCH (n1:Label), (n2:Label)
WHERE n1.prop = n2.prop AND NOT n1 = n2
RETURN n1, n2

Relationship property uniqueness constraint

MATCH ()-[r1:REL_TYPE]->(), ()-[r2:REL_TYPE]->()
WHERE r1.prop = r2.prop AND NOT r1 = r2
RETURN r1, r2

Node property existence constraint

MATCH (n:Label)
WHERE n.prop IS NULL
RETURN n

Relationship property existence constraint

MATCH ()-[r:REL_TYPE]->()
WHERE r.prop IS NULL
RETURN r

Node property type constraint

MATCH (n:Label)
WHERE n.prop IS NOT :: <TYPE>
RETURN n

Relationship property type constraint

MATCH ()-[r:REL_TYPE]->()
WHERE r.prop IS NOT :: <TYPE>
RETURN r

Node key constraint

MATCH (n1:Label), (n2:Label)
WHERE n1.prop = n2.prop AND NOT n1 = n2
UNWIND [n1, n2] AS node
RETURN node, 'non-unique' AS reason
UNION
MATCH (n:Label)
WHERE n.prop IS NULL
RETURN n AS node, 'non-existing' AS reason

Relationship key constraint

MATCH ()-[r1:REL_TYPE]->(), ()-[r2:REL_TYPE]->()
WHERE r1.prop = r2.prop AND NOT r1 = r2
UNWIND [r1, r2] AS relationship
RETURN relationship, 'non-unique' AS reason
UNION
MATCH ()-[r:REL_TYPE]->()
WHERE r.prop IS NULL
RETURN r AS relationship, 'non-existing' AS reason

SHOW CONSTRAINTS

To list all constraints with the default output columns, use SHOW CONSTRAINTS. If all columns are required, use SHOW CONSTRAINTS YIELD *. For the full command syntax to list constraints, see Syntax → SHOW CONSTRAINTS.

One of the output columns from SHOW CONSTRAINTS is the name of the constraint. This can be used to drop the constraint with the DROP CONSTRAINT command.

Listing constraints requires the SHOW CONSTRAINTS privilege.
Example 47. List all constraints with default output columns
Query
SHOW CONSTRAINTS
Result
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                          | type                              | entityType     | labelsOrTypes  | properties                         | ownedIndex                    | propertyType                     |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 21 | "actor_fullname"              | "NODE_KEY"                        | "NODE"         | ["Actor"]      | ["firstname", "surname"]           | "actor_fullname"              | NULL                             |
| 10 | "author_name"                 | "NODE_PROPERTY_EXISTENCE"         | "NODE"         | ["Author"]     | ["name"]                           | NULL                          | NULL                             |
| 3  | "book_isbn"                   | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["isbn"]                           | "book_isbn"                   | NULL                             |
| 7  | "book_title_year"             | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["title", "publicationYear"]       | "book_title_year"             | NULL                             |
| 17 | "director_imdbId"             | "NODE_KEY"                        | "NODE"         | ["Director"]   | ["imdbId"]                         | "director_imdbId"             | NULL                             |
| 23 | "knows_since_how"             | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["KNOWS"]      | ["since", "how"]                   | "knows_since_how"             | NULL                             |
| 14 | "movie_tagline"               | "NODE_PROPERTY_TYPE"              | "NODE"         | ["Movie"]      | ["tagline"]                        | NULL                          | "STRING | LIST<STRING NOT NULL>" |
| 12 | "movie_title"                 | "NODE_PROPERTY_TYPE"              | "NODE"         | ["Movie"]      | ["title"]                          | NULL                          | "STRING"                         |
| 25 | "node_uniqueness_param"       | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["prop1"]                          | "node_uniqueness_param"       | NULL                             |
| 19 | "ownershipId"                 | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["OWNS"]       | ["ownershipId"]                    | "ownershipId"                 | NULL                             |
| 13 | "part_of"                     | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["order"]                          | NULL                          | "INTEGER"                        |
| 15 | "part_of_tags"                | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["tags"]                           | NULL                          | "STRING | LIST<STRING NOT NULL>" |
| 9  | "prequels"                    | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"]                | "prequels"                    | NULL                             |
| 26 | "rel_exist_param"             | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["published"]                      | NULL                          | NULL                             |
| 5  | "sequels"                     | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["SEQUEL_OF"]  | ["order"]                          | "sequels"                     | NULL                             |
| 11 | "wrote_year"                  | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["year"]                           | NULL                          | NULL                             |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Example 48. List all constraints with full details

To return the full details of the constraints on a database, use SHOW CONSTRAINTS YIELD *

List all constraints with YIELD *
SHOW CONSTRAINTS YIELD *
Result
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                          | type                              | entityType     | labelsOrTypes  | properties                         | ownedIndex                    | propertyType                     | options                                       | createStatement                                                                                                                        |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 21 | "actor_fullname"              | "NODE_KEY"                        | "NODE"         | ["Actor"]      | ["firstname", "surname"]           | "actor_fullname"              | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY"                                  |
| 10 | "author_name"                 | "NODE_PROPERTY_EXISTENCE"         | "NODE"         | ["Author"]     | ["name"]                           | NULL                          | NULL                             | NULL                                          | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL"                                                      |
| 3  | "book_isbn"                   | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["isbn"]                           | "book_isbn"                   | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE"                                                            |
| 7  | "book_title_year"             | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["title", "publicationYear"]       | "book_title_year"             | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE"                                |
| 17 | "director_imdbId"             | "NODE_KEY"                        | "NODE"         | ["Director"]   | ["imdbId"]                         | "director_imdbId"             | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY"                                              |
| 23 | "knows_since_how"             | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["KNOWS"]      | ["since", "how"]                   | "knows_since_how"             | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY"                           |
| 14 | "movie_tagline"               | "NODE_PROPERTY_TYPE"              | "NODE"         | ["Movie"]      | ["tagline"]                        | NULL                          | "STRING | LIST<STRING NOT NULL>" | NULL                                          | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST<STRING NOT NULL>"                         |
| 12 | "movie_title"                 | "NODE_PROPERTY_TYPE"              | "NODE"         | ["Movie"]      | ["title"]                          | NULL                          | "STRING"                         | NULL                                          | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING"                                                     |
| 25 | "node_uniqueness_param"       | "UNIQUENESS"                      | "NODE"         | ["Book"]       | ["prop1"]                          | "node_uniqueness_param"       | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE"                                               |
| 19 | "ownershipId"                 | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["OWNS"]       | ["ownershipId"]                    | "ownershipId"                 | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY"                                   |
| 13 | "part_of"                     | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["order"]                          | NULL                          | "INTEGER"                        | NULL                                          | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER"                                                |
| 15 | "part_of_tags"                | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["tags"]                           | NULL                          | "STRING | LIST<STRING NOT NULL>" | NULL                                          | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST<STRING NOT NULL>"                     |
| 9  | "prequels"                    | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"]                | "prequels"                    | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE"                                    |
| 26 | "rel_exist_param"             | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["published"]                      | NULL                          | NULL                             | NULL                                          | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL"                                        |
| 5  | "sequels"                     | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["SEQUEL_OF"]  | ["order"]                          | "sequels"                     | NULL                             | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE"                                                  |
| 11 | "wrote_year"                  | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["year"]                           | NULL                          | NULL                             | NULL                                          | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL"                                                  |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
The type column returns UNIQUENESS for the node property uniqueness constraint and RELATIONSHIP_UNIQUENESS for the relationship property uniqueness constraint. This will be updated in a future version of Neo4j. Node property uniqueness constraints will be updated to NODE_PROPERTY_UNIQUENESS and relationship property uniqueness constraints to RELATIONSHIP_PROPERTY_UNIQUENESS.

Listing constraints with filtering

The SHOW CONSTRAINTS command can be filtered in various ways. The filtering of rows can be done using constraint type keywords or a WHERE clause, while filtering of columns is achieved by specifying the desired columns in a YIELD clause.

Example 49. List only specific constraint types
List only key constraints
SHOW KEY CONSTRAINTS
Result
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                       | type               | entityType     | labelsOrTypes | properties               | ownedIndex                 | propertyType |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 21 | "actor_fullname"           | "NODE_KEY"         | "NODE"         | ["Actor"]     | ["firstname", "surname"] | "actor_fullname"           | NULL         |
| 17 | "director_imdbId"          | "NODE_KEY"         | "NODE"         | ["Director"]  | ["imdbId"]               | "director_imdbId"          | NULL         |
| 23 | "knows_since_how"          | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"]     | ["since", "how"]         | "knows_since_how"          | NULL         |
| 19 | "ownershipId"              | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"]      | ["ownershipId"]          | "ownershipId"              | NULL         |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+

For a full list of all the constraint types (and synonyms) available in this command see Syntax → SHOW CONSTRAINTS.

Example 50. Filtering constraints using the WHERE clause
List only constraints with a RELATIONSHIP entityType
SHOW CONSTRAINTS
WHERE entityType = 'RELATIONSHIP'
Result
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name                          | type                              | entityType     | labelsOrTypes  | properties                         | ownedIndex                    | propertyType                     |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 23 | "knows_since_how"             | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["KNOWS"]      | ["since", "how"]                   | "knows_since_how"             | NULL                             |
| 19 | "ownershipId"                 | "RELATIONSHIP_KEY"                | "RELATIONSHIP" | ["OWNS"]       | ["ownershipId"]                    | "ownershipId"                 | NULL                             |
| 13 | "part_of"                     | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["order"]                          | NULL                          | "INTEGER"                        |
| 15 | "part_of_tags"                | "RELATIONSHIP_PROPERTY_TYPE"      | "RELATIONSHIP" | ["PART_OF"]    | ["tags"]                           | NULL                          | "STRING | LIST<STRING NOT NULL>" |
| 9  | "prequels"                    | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"]                | "prequels"                    | NULL                             |
| 26 | "rel_exist_param"             | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["published"]                      | NULL                          | NULL                             |
| 5  | "sequels"                     | "RELATIONSHIP_UNIQUENESS"         | "RELATIONSHIP" | ["SEQUEL_OF"]  | ["order"]                          | "sequels"                     | NULL                             |
| 11 | "wrote_year"                  | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"]      | ["year"]                           | NULL                          | NULL                             |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Example 51. Returning specific columns for all constraints

It is possible to return only specific columns of the available constraints using the YIELD clause:

List only the name, type, and createStatement columns
SHOW CONSTRAINTS
YIELD name, type, createStatement
Result
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name                          | type                              | createStatement                                                                                                                        |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "actor_fullname"              | "NODE_KEY"                        | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY"                                  |
| "author_name"                 | "NODE_PROPERTY_EXISTENCE"         | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL"                                                      |
| "book_isbn"                   | "UNIQUENESS"                      | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE"                                                            |
| "book_title_year"             | "UNIQUENESS"                      | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE"                                |
| "constraint_with_provider"    | "NODE_KEY"                        | "CREATE CONSTRAINT `constraint_with_provider` FOR (n:`Actor`) REQUIRE (n.`surname`) IS NODE KEY"                                       |
| "director_imdbId"             | "NODE_KEY"                        | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY"                                              |
| "knows_since_how"             | "RELATIONSHIP_KEY"                | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY"                           |
| "movie_tagline"               | "NODE_PROPERTY_TYPE"              | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST<STRING NOT NULL>"                         |
| "movie_title"                 | "NODE_PROPERTY_TYPE"              | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING"                                                     |
| "node_uniqueness_param"       | "UNIQUENESS"                      | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE"                                               |
| "ownershipId"                 | "RELATIONSHIP_KEY"                | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY"                                   |
| "part_of"                     | "RELATIONSHIP_PROPERTY_TYPE"      | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER"                                                |
| "part_of_tags"                | "RELATIONSHIP_PROPERTY_TYPE"      | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST<STRING NOT NULL>"                     |
| "prequels"                    | "RELATIONSHIP_UNIQUENESS"         | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE"                                    |
| "rel_exist_param"             | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL"                                        |
| "sequels"                     | "RELATIONSHIP_UNIQUENESS"         | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE"                                                  |
| "wrote_year"                  | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL"                                                  |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Result columns for listing constraints

Table 4. Listing constraints output
Column Description Type

id

The id of the constraint. Default Output

INTEGER

name

Name of the constraint (explicitly set by the user or automatically assigned). Default Output

STRING

type

The ConstraintType of this constraint (UNIQUENESS (node uniqueness), RELATIONSHIP_UNIQUENESS, NODE_PROPERTY_EXISTENCE, RELATIONSHIP_PROPERTY_EXISTENCE, NODE_PROPERTY_TYPE, RELATIONSHIP_PROPERTY_TYPE, NODE_KEY, or RELATIONSHIP_KEY). Default Output

UNIQUENESS and RELATIONSHIP_UNIQUENESS will be updated to say NODE_PROPERTY_UNIQUENESS and RELATIONSHIP_PROPERTY_UNIQUENESS respectively in a future version of Neo4j.

STRING

entityType

Type of entities this constraint represents (NODE or RELATIONSHIP). Default Output

STRING

labelsOrTypes

The labels or relationship types of this constraint. The list returned will only include a single value (the name of the constrained node label or relationship type). Default Output

LIST<STRING>

properties

The properties of this constraint. Default Output

LIST<STRING>

ownedIndex

The name of the index associated with the constraint or null, in case no index is associated with it. Default Output

STRING

propertyType

The property type the property is restricted to for property type constraints, or null for the other constraints. Default Output Introduced in 5.9

STRING

options

The options passed to CREATE command, for the index associated to the constraint, or null if no index is associated with the constraint.

MAP

createStatement

Statement used to create the constraint.

STRING

DROP CONSTRAINT

Constraints are dropped using the DROP CONSTRAINT command. For the full command syntax to drop constraints, see Syntax → DROP CONSTRAINT.

Dropping a constraint requires the DROP CONSTRAINT privilege.

Drop a constraint by name

A constraint can be dropped using the name with the DROP CONSTRAINT constraint_name command. It is the same command for all constraint types. The name of the constraint can be found using the SHOW CONSTRAINTS command, given in the output column name.

Example 52. Drop a constraint by name
Drop the constraint book_isbn
DROP CONSTRAINT book_isbn
Result
Removed 1 constraint.

Drop a constraint with a parameter

Constraints can be dropped with a parameterized name.

Example 53. Drop a constraint using a parameter
Parameters
{
  "name": "actor_fullname"
}
Drop a constraint with a parameterized name
DROP CONSTRAINT $name
Result
Removed 1 constraint.

Drop a non-existing constraint

If it is uncertain if any constraint with a given name exists and you want to drop it if it does but not get an error should it not, use IF EXISTS. This will ensure that no error is thrown. As of Neo4j 5.17, an informational notification is returned stating that the constraint does not exist.

Example 54. Drop a non-existing constraint
Drop the non-existing constraint missing_constraint_name
DROP CONSTRAINT missing_constraint_name IF EXISTS
Result
(no changes, no records)
Notification
`DROP CONSTRAINT missing_constraint_name IF EXISTS` has no effect. `missing_constraint_name` does not exist.