The DELETE clause removes nodes and relationships from a graph database. Use MATCH to identify the graph pattern first, then DELETE the matched elements. section 3.1.6
Use deletion queries in these ways:
- Delete a relationship by matching its endpoint nodes and binding the relationship variable. section 3.1.6
- Delete a node with DELETE when it has no relationships attached. section 3.1.6
- Use DETACH DELETE when a node still has relationships; it removes those relationships before removing the node. section 3.1.6
- Use MATCH (n) DETACH DELETE n to remove every node and relationship in the database. section 3.1.6
Deleting a relationship
MATCH (n:Person)-[r]->(m:Person) WHERE n.name = 'Satish' AND m.name = 'Elaine' DELETE r. The relationship type is omitted, so the pattern searches for any relationship between the matched people. section 3.1.6
Listing 3.27 Cypher statement that deletes a single node and all its relationships from the database by using the DETACH DELETE clause
MATCH (n:Person) WHERE n.name = 'Elaine' DETACH DELETE n
Inspect the complete DETACH DELETE query for removing Elaine and all relationships attached to her. section 3.1.6
