DELETE
Introduction
For removing properties and labels, see REMOVE.
Remember that you cannot delete a node without also deleting relationships that start or end on said node.
Either explicitly delete the relationships, or use DETACH DELETE
.
The examples start out with the following database:
N0 [ label = "{Person|name = \'Andy\'\lage = 36\l}" ] N0 -> N1 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N0 -> N2 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N1 [ label = "{Person|name = \'Timothy\'\lage = 25\l}" ] N2 [ label = "{Person|name = \'Peter\'\lage = 34\l}" ] N3 [ label = "{Person|name = \'UNKNOWN\'\l}" ]
Delete single node
To delete a node, use the DELETE
clause.
MATCH (n:Person {name: 'UNKNOWN'})
DELETE n
|
Rows: 0 |
Delete all nodes and relationships
This query is not for deleting large amounts of data, but is useful when experimenting with small example data sets.
MATCH (n)
DETACH DELETE n
|
Rows: 0 |
Delete a node with all its relationships
When you want to delete a node and any relationship going to or from it, use DETACH DELETE
.
MATCH (n {name: 'Andy'})
DETACH DELETE n
|
Rows: 0 |
For |
Delete relationships only
It is also possible to delete relationships only, leaving the node(s) otherwise unaffected.
MATCH (n {name: 'Andy'})-[r:KNOWS]->()
DELETE r
This deletes all outgoing KNOWS
relationships from the node with the name 'Andy'.
|
Rows: 0 |