Nodes, Relationships & Cypher Basics
The Graph Data Model
Nodes (entities) and Relationships (connections) are both first-class, and both can carry properties — a relationship isn't just an implied foreign key, it can hold its own data (e.g. PURCHASED.quantity, FRIENDS_WITH.since). A Label (:Person) categorizes a node roughly like a table name, but a node can carry multiple labels at once, unlike a row belonging to exactly one table.
Cypher — Pattern-Matching Queries
// find a node
MATCH (p:Person {name: "Ada"}) RETURN p
// traverse a relationship — one query, no JOINs
MATCH (a:Person {name: "Ada"})-[:FRIENDS_WITH]->(friend:Person)
RETURN friend
// filter with WHERE, like SQL's WHERE
MATCH (p:Person) WHERE p.age > 30 RETURN pCypher's ASCII-art-like syntax ((a)-[:TYPE]->(b)) visually mirrors the graph shape being described — a deliberate readability choice distinct from SQL's row/table-oriented syntax.
Creating Data
CREATE (a:Person {name: "Ada"})
MATCH (a:Person {name: "Ada"}), (b:Person {name: "Bob"})
CREATE (a)-[:FRIENDS_WITH {since: 2020}]->(b)
// MERGE = match-or-create, avoids duplicate nodes on re-run
MERGE (p:Person {email: "ada@example.com"})
ON CREATE SET p.createdAt = timestamp()Deleting Nodes with Relationships
// plain DELETE fails if the node still has relationships attached
MATCH (p:Person {name: "Ada"}) DETACH DELETE p
// removes the node AND every relationship connected to it in one stepKeep your own version of these notes — editable, searchable, and organised by your stack.
Start free