What's the Cypher script to delete a node by ID?

Rm558 picture Rm558 · Jan 26, 2015 · Viewed 20.7k times · Source

In SQL:

Delete From Person Where ID = 1;

In Cypher, what's the script to delete a node by ID?

(Edited: ID = Neo4j's internal Node ID)

Answer

Luanne picture Luanne · Jan 26, 2015

Assuming you're referring to Neo4j's internal node id:

MATCH (p:Person) where ID(p)=1
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p

If you're referring to your own property 'id' on the node:

 MATCH (p:Person {id:1})
 OPTIONAL MATCH (p)-[r]-() //drops p's relations
 DELETE r,p