Knowledge Base

How to implement a primary key property for a label

Commencing with Neo4j 2.3.x it is possible to create the equivalent of a primary key on a property of a label. For example the following Cypher:

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

will create two constraints on the property isbn of nodes with label Book and ensure that when a new Book node is created, its isbn must be defined, and that it must be unique across all nodes with the Book label.

Property existence constraints are only available in the Neo4j Enterprise Edition. Databases with property existence constraints cannot be opened using Neo4j Community Edition.