neo4j官网地址
1、创建节点
create (<node-name>:<label-name>)
eg:
create (s:Student)
2、创建带属性的节点
create (<node-name>:<label-name> {
<property1-name>:<property1-Value>,
<property2-name>:<property2-Value>,
...,
<property3-name>:<property3-Value>
})
eg:
create (s:Student{id = 1,name = "李世民",age=2000})
3、merge
merge (a:Person {name:"李世民"})
merge (b:Person {name:"李治"})
merge (b)-[:SON]->(a)
merge (p:Person {name: "嬴政"})
on create set p.age = 30
on match set p.height = 190
1、查询全部
match (s:Student) return s;
2、查询部分
match (s:Student) return s.id,s.name;
3、按条件查询
match (s:Student) where s.age > 20 return s.id,s.name;
4、排序
match (s:Student) where s.age < 20 return s.id,s.name order by s.age desc;
5、分组
match (s:Student) where s.age < 20 return s.id,count(*);
6、limit语句
match (s:Student) where s.age < 20 return s.id,s.name limit 3;
match (s:Student) where s.age < 20 return s.id,s.name skip 2 limit 3;
1、创建关系
create (t:Teacher{id:20001,name:"王老师",age:35,teach:"语文"}) return t
match (t:Teacher),(s:Student) where s.age < 20
create (t)-[teach:Teach]->(s)
return t,teach,s;
2、查询全部关系
match (a)-[b]-(c) return a,b,c;
match (s:Student) where s.name = '李世民' set s.age = 2000 return s;
1、删除部分节点
match (s:Student) where s.age < 20 delete s;
注:若节点有关系需先删除关系
match (t:Teacher)-[teach]->(s:Student) where s.age < 20 delete teach,s;
2、删除整个节点
match (s:Student) delete s;
3、删除全部节点以及关系(慎用!)
match (n) detach delete n
4、删除节点的属性
match (s:Student{name:"李世民"}) remove s.age;