Neo4j (Graph Database) Cheat Sheet
Cypher query language essentials for creating nodes and relationships, traversing graphs, and finding shortest paths in Neo4j.
2 PagesIntermediateMar 12, 2026
Creating Nodes & Relationships
Basic graph creation in Cypher.
sql
// Create nodesCREATE (a:Person {name: "Alice", age: 30})CREATE (b:Person {name: "Bob", age: 25})// Create a relationship between existing nodesMATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})CREATE (a)-[:FRIENDS_WITH {since: 2020}]->(b)
Querying & Traversal
Matching patterns and finding paths.
sql
// Find a nodeMATCH (p:Person {name: "Alice"}) RETURN p// Traverse a relationshipMATCH (a:Person)-[:FRIENDS_WITH]->(b:Person)RETURN a.name, b.name// Shortest path between two nodesMATCH path = shortestPath( (a:Person {name: "Alice"})-[*]-(b:Person {name: "Bob"}))RETURN path
Update, Delete & Merge
Modifying the graph safely.
sql
MATCH (p:Person {name: "Alice"})SET p.age = 31MATCH (p:Person {name: "Bob"})DETACH DELETE p // deletes the node and its relationshipsMERGE (p:Person {name: "Carol"})ON CREATE SET p.createdAt = timestamp()
Core Concepts
Terminology behind Neo4j's property graph model.
- Node- an entity with a label (e.g. :Person) and key-value properties
- Relationship- a directed, typed connection between two nodes; can hold properties
- Label- a tag categorizing a node; a node may have multiple labels
- MATCH- the Cypher clause for pattern matching against the graph
- MERGE- "find or create": matches a pattern or creates it if absent
- CREATE CONSTRAINT ... IS UNIQUE- enforces uniqueness and backs it with an index
Pro Tip
Use MERGE only on the smallest pattern that must be unique, then attach ON CREATE SET / ON MATCH SET for the rest — merging on a large multi-property pattern can silently create duplicate nodes when any single property fails to match.
Was this cheat sheet helpful?
Explore Topics
#Neo4jGraphDatabase#Neo4jGraphDatabaseCheatSheet#Database#Intermediate#CreatingNodesRelationships#QueryingTraversal#UpdateDeleteMerge#CoreConcepts#DataStructures#Databases#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance