在SQL中:
Delete From Person Where ID = 1;
在Cypher中,按ID删除节点的脚本是什么?
(已编辑:ID = Neo4j'内部节点ID)
答案 0 :(得分:40)
假设您指的是Neo4j的内部节点ID:
MATCH (p:Person) where ID(p)=1
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p
如果您在节点上引用自己的属性“id”:
MATCH (p:Person {id:1})
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p
答案 1 :(得分:19)
具有id" xx"的节点的最干净扫描是
MATCH(n)其中id(n)= xx DETACH DELETE n
(https://neo4j.com/docs/developer-manual/current/cypher/#delete-delete-all-nodes-and-relationships)
答案 2 :(得分:2)
当节点是孤儿时。
Start n=node(1)
Delete n;
答案 3 :(得分:1)
原来的问题已经回答,但是要删除具有关系的节点,请使用Neo.ClientError.Schema.ConstraintValidationFailed: Cannot delete node<21>, because it still has relationships. To delete this node, you must first delete its relationships.
CASCADE
否则,您会得到:
{{1}}
这就像SQL的{{1}}
答案 4 :(得分:0)
按照@ saad-khan提供的链接,这是获取节点和关系ID的示例。 下面的代码显示了ID,因此您可以确保删除与给定ID相关的所有内容。
MATCH (node)-[relation:HAS]->(value)
where ID(node)=1234
RETURN ID(instance), ID(value), ID(r)
Ps。:“:HAS”是关系的一个例子。