17.2. Constraints

17.2.1. Create uniqueness constraint
17.2.2. Drop uniqueness constraint

Neo4j helps enforce data integrity with the use of constraints.

You can use unique constraints to ensure that property values are unique for all nodes with a specific label. Unique constraints do not mean that all nodes have to have a unique value for the properties — nodes without the property are not subject to this rule.

Remember that adding constraints is an atomic operation that can take a while — all existing data has to be scanned before Neo4j can turn the constraint “on”.

You can have multiple unique constraints for a given label.

17.2.1. Create uniqueness constraint

To create a constraint that makes sure that your database will never contain more than one node with a specificlabel and one property value, use the IS UNIQUE syntax.

Query. 

CREATE CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE

Result

Constraints added: 1

(empty result)


17.2.2. Drop uniqueness constraint

By using DROP CONSTRAINT, you remove a constraint from the database.

Query. 

DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE

Result

Constraints removed: 1

(empty result)