Deleting graph elements — nodes and relationships, is done with DELETE
.
For removing properties and labels, see Section 11.6, “Remove”.
The examples start out with the following database:
To delete a node, use the DELETE
clause.
Query.
MATCH (n { name: 'Peter' }) DELETE n
Nothing is returned from this query, except the count of affected nodes.
Try this query live. create (_0 {`age`:25, `name`:"Tobias"}) create (_1 {`age`:34, `name`:"Peter"}) create (_2 {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 match (n {name: 'Peter'}) delete n
If you are trying to delete a node with relationships on it, you have to delete these as well.
Query.
MATCH (n { name: 'Andres' })-[r]-() DELETE n, r
Nothing is returned from this query, except the count of affected nodes.
Try this query live. create (_0 {`age`:25, `name`:"Tobias"}) create (_1 {`age`:34, `name`:"Peter"}) create (_2 {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 match (n {name: 'Andres'})-[r]-() delete n, r
This query isn’t for deleting large amounts of data, but is nice when playing around with small example data sets.
Query.
MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r
Nothing is returned from this query, except the count of affected nodes.
Try this query live. create (_0 {`age`:25, `name`:"Tobias"}) create (_1 {`age`:34, `name`:"Peter"}) create (_2 {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r
Copyright © 2014 Neo Technology