Overview
The DELETE
statement allows you to delete nodes and edges from a graph. These nodes or edges must first be retrieved using the MATCH
statement.
An edge cannot exist when any of its endpoints is removed from the graph. Therefore, by default GQL does not allow to delete a node while it still has edges connected to it. You can bypass this restriction by explicitly using the keyword DETACH
to enable the deletion of nodes along with their connected edges. For example, when node B
is deleted by DETACH DELETE
, edges 1
, 2
and 4
will also be deleted.

In the case of DELETE
or NODETACH DELETE
, the deletion of node B
will fail, which can be useful as a security measure to prevent unintended deletions. If not explicitly specified, NODETACH
is applied.
Example Graph

CREATE GRAPH myGraph ANY
INSERT (rowlock:User {_id: "U01", name: "rowlock"}),
(brainy:User {_id: "U02", name: "Brainy"}),
(mochaeach:User {_id: "U03", name: "mochaeach"}),
(purplechalk:User {_id: "U04", name: "purplechalk"}),
(lionbower:User {_id: "U05", name: "lionbower"}),
(c:Club {_id: "C01"}),
(rowlock)-[:Follows]->(brainy),
(mochaeach)-[:Follows]->(brainy),
(brainy)-[:Joins]->(c)
Deleting Isolated Nodes
To delete the isolated nodes purplechalk
and lionbower
:
MATCH (n:User) WHERE n.name IN ["purplechalk", "lionbower"]
DELETE n
The [NODETACH] DELETE
statement can only delete isolated nodes, if any node specified has connected edges, an error will be thrown, and no nodes will be deleted.
Deleting Any Nodes
To delete the node rowlock
along with its connected edges:
MATCH (n:User {name: 'rowlock'})
DETACH DELETE n
Deleting All Nodes and Edges
To delete all nodes along with all edges:
MATCH (n)
DETACH DELETE n
Deleting Edges
To delete all Follows
edges:
MATCH ()-[e:Follows]->()
DELETE e
Limiting the Amount to Delete
To limit the number of nodes or edges to delete, apply the LIMIT
statement after MATCH
to keep only the first N records before passing the variable to the DELETE
statement.
To delete any two edges:
MATCH ()-[e]->() LIMIT 2
DELETE e