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:

Diagram

Delete single node

To delete a node, use the DELETE clause.

Query
MATCH (n:Person {name: 'UNKNOWN'})
DELETE n
Table 1. Result

(empty result)

Rows: 0
Nodes deleted: 1

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. When deleting large amounts of data, use CALL { } IN TRANSACTIONS.

Query
MATCH (n)
DETACH DELETE n
Table 2. Result

(empty result)

Rows: 0
Nodes deleted: 4
Relationships deleted: 2

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: 'Andy'})
DETACH DELETE n
Table 3. Result

(empty result)

Rows: 0
Nodes deleted: 1
Relationships deleted: 2

For DETACH DELETE for users with restricted security privileges, see Operations Manual → Fine-grained access control.

Delete relationships only

It is also possible to delete relationships only, leaving the node(s) otherwise unaffected.

Query
MATCH (n {name: 'Andy'})-[r:KNOWS]->()
DELETE r

This deletes all outgoing KNOWS relationships from the node with the name 'Andy'.

Table 4. Result

(empty result)

Rows: 0
Relationships deleted: 2