12.4. Delete

The DELETE clause is used to delete graph elements — nodes, relationships or paths.

For removing properties and labels, see Section 12.5, “Remove”. Remember that you can not 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:

Delete single node

To delete a node, use the DELETE clause.

Query 

MATCH (n:Useless)
DELETE n

Result

Nodes deleted: 1

(empty result)

Try this query live create (_0 {`age`:36, `name`:"Andres"}) create (_1 {`age`:25, `name`:"Tobias"}) create (_2 {`age`:34, `name`:"Peter"}) create (_0)-[:`KNOWS`]->(_2) create (_0)-[:`KNOWS`]->(_1) match (n:Useless) delete n

Delete all nodes and relationships

This query isn’t for deleting large amounts of data, but is nice when playing around with small example data sets.

Query 

MATCH (n)
DETACH DELETE n

Result

Nodes deleted: 3
Relationships deleted: 2

(empty result)

Try this query live create (_0 {`age`:36, `name`:"Andres"}) create (_1 {`age`:25, `name`:"Tobias"}) create (_2 {`age`:34, `name`:"Peter"}) create (_0)-[:`KNOWS`]->(_2) create (_0)-[:`KNOWS`]->(_1) MATCH (n) DETACH DELETE n

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.

Query 

MATCH (n { name:'Andres' })
DETACH DELETE n

Result

Nodes deleted: 1
Relationships deleted: 2

(empty result)

Try this query live create (_0 {`age`:36, `name`:"Andres"}) create (_1 {`age`:25, `name`:"Tobias"}) create (_2 {`age`:34, `name`:"Peter"}) create (_0)-[:`KNOWS`]->(_2) create (_0)-[:`KNOWS`]->(_1) MATCH (n {name:'Andres'}) DETACH DELETE n