我们不再单独介绍CQL语法,只写一个简单的例子帮助你建立使用CQL的感觉
将下面代码复制到Neo4J的命令框中,执行;
注意:
-
逐行复制创建节点实体代码去执行;
-
创建关系时三句一起复制,不要带注释;
// 创建生物实体节点
CREATE (biological:Biological {name: "Biological"})// 创建植物节点
CREATE (plant:Plant {name: "Plant1"})
// 创建草药节点
CREATE (herb:Herb {name: "Herb1"})// 创建动物节点
CREATE (animal:Animal {name: "Animal"})// 创建动物子节点
CREATE (dog:Animal {name: "Dog"})
CREATE (cow:Animal {name: "Cow"})// 草药是植物
MATCH (herb:Herb), (plant:Plant)
WHERE herb.name = "Herb1" AND plant.name = "Plant1"
CREATE (herb)-[:IS_A]->(plant)// 植物是生物
MATCH (plant:Plant), (biological:Biological)
WHERE plant.name = "Plant1" AND biological.name = "Biological"
CREATE (plant)-[:IS_A]->(biological)// 动物是生物
MATCH (animal:Animal), (biological:Biological)
WHERE animal.name = "Animal" AND biological.name = "Biological"
CREATE (animal)-[:IS_A]->(biological)//狗是动物
MATCH (dog:Animal), (animal:Animal)
WHERE dog.name = "Dog" AND animal.name = "Animal"
CREATE (dog)-[:IS_A]->(animal)//牛是动物
MATCH (cow:Animal), (animal:Animal)
WHERE cow.name = "Cow" AND animal.name = "Animal"
CREATE (cow)-[:IS_A]->(animal)// 牛吃草药
MATCH (cow:Animal {name: "Cow"}), (herb:Herb {name: "Herb1"})
WHERE cow.name = "Cow" AND herb.name = "Herb1"
CREATE (cow)-[:EATS]->(herb)// 删除所有的节点和关系
MATCH (n:Herb) DETACH DELETE n
// 删除所有植物相关的节点和关系
MATCH (n:Plant) DETACH DELETE n
// 删除所有动物相关的节点和关系
MATCH (n:Animal) DETACH DELETE n
// 删除所有生物实体相关的节点和关系
MATCH (n:Biological) DETACH DELETE n