DELETE
The DELETE clause is used to remove nodes and relationships from the graph.
Important Behavior
⚠️ Note: Deleting a node automatically deletes all of its incoming and outgoing relationships. You cannot have orphaned relationships in the graph.
Deleting Nodes
To delete a node and all of its relationships:
GRAPH.QUERY DEMO_GRAPH "MATCH (p:Person {name:'Jim'}) DELETE p"
Deleting Relationships
To delete specific relationships:
GRAPH.QUERY DEMO_GRAPH "MATCH (:Person {name:'Jim'})-[r:FRIENDS]->() DELETE r"
This query deletes all outgoing FRIENDS relationships from the node with name ‘Jim’, while keeping the nodes intact.
Common Patterns
Delete all nodes and relationships in a graph
GRAPH.QUERY DEMO_GRAPH "MATCH (n) DETACH DELETE n"
The DETACH DELETE automatically removes all relationships before deleting the node.
Conditional deletion
GRAPH.QUERY DEMO_GRAPH "MATCH (p:Person) WHERE p.age < 18 DELETE p"
Deletes all Person nodes where age is less than 18.
Frequently Asked Questions 4
What happens to relationships when I delete a node?
Deleting a node automatically deletes all of its incoming and outgoing relationships. FalkorDB does not allow orphaned relationships in the graph.
What is the difference between DELETE and DETACH DELETE?
In FalkorDB, DELETE actually implements DETACH DELETE behavior — relationships are automatically removed when their endpoint nodes are deleted. Both keywords work the same way.
How do I delete all data in a graph?
Use MATCH (n) DETACH DELETE n to remove all nodes and their relationships. Alternatively, use the GRAPH.DELETE command to remove the entire graph key.
Can I delete specific relationships without deleting nodes?
Yes. Match the relationship with an alias and delete only it: MATCH (a)-[r:KNOWS]->(b) DELETE r. The nodes remain intact.