A unique constraint is a database rule requiring a property value to be unique among nodes with a particular label. In Neo4j, it protects data integrity during imports and automatically creates an index for that property. section 3.2.3
Use unique constraints to:
- Prevent duplicate identifiers, such as multiple User nodes with the same id. section 3.2.3
- Stop an import query that would compromise data integrity. section 3.2.3
- Improve import and analytical query performance through the automatically created index. section 3.2.3
- Model identifier rules for each label independently, such as User.id, Tweet.id, or Tag.id. section 3.2.3 section 7.1
Constraining imported graph identifiers
Define constraints before importing nodes. These statements allow one User per id and one Tweet per id: CREATE CONSTRAINT IF NOT EXISTS FOR (u:User) REQUIRE u.id IS UNIQUE; CREATE CONSTRAINT IF NOT EXISTS FOR (p:Tweet) REQUIRE p.id IS UNIQUE;. For extracted hashtags, apply the same pattern to Tag.id before MERGE creates or reuses Tag nodes. section 3.2.3 section 7.1






