Cypher's pattern syntax is used for both writing and reading, so learning CREATE teaches the shape of every query.
Cypher describes graph data with ASCII-art patterns. A node is written in parentheses, (p:Person {name: 'Ann'}), where p is a variable you can refer to later in the query, :Person a label and the braces hold properties. A relationship is written as an arrow with brackets, -[:FOLLOWS {since: 2021}]->.
CREATE writes exactly the pattern you give it:
CREATE (a:Person {name: 'Ann'})-[:FOLLOWS]->(b:Person {name: 'Bob'})creates two nodes and one relationship. Within one statement you can reuse variables to connect things you just created. To connect existing nodes, first find them with MATCH, then CREATE only the relationship.
Relationships must have a type and a direction when created; you cannot create an undirected relationship. You can still ignore direction when querying.
CREATE always creates new data. Running the same CREATE twice gives you two Anns, which is the most common beginner mistake. For "create if it does not exist", use MERGE (next lessons).
A node can carry several labels, (:Person:Employee). Labels and relationship types are conventionally PascalCase and UPPER_SNAKE_CASE; property keys are camelCase.
Example
// three people, a company, and who follows whom
CREATE (ann:Person {name: 'Ann', born: 1990}),
(bob:Person {name: 'Bob', born: 1985}),
(cy:Person {name: 'Cy', born: 2001}),
(acme:Company {name: 'Acme'}),
(ann)-[:FOLLOWS {since: 2021}]->(bob),
(cy)-[:FOLLOWS {since: 2023}]->(bob),
(bob)-[:WORKS_AT]->(acme);
// connect existing nodes: MATCH them, then CREATE the relationship
MATCH (a:Person {name: 'Ann'}), (c:Person {name: 'Cy'})
CREATE (a)-[:FOLLOWS {since: 2024}]->(c);
// Added 1 relationship, set 1 propertyRemember
- Nodes
(v:Label {k: v}), relationships-[:TYPE {k: v}]-> - Variables connect parts of a pattern within one statement
- CREATE always adds new data, even if identical data exists
- Relationships are created with a type and a direction
Watch out for
- Re-running a CREATE script and ending up with duplicate nodes.