1.介绍
2.实战
Neo4j的sql语句
1.创建多个节点
CREATE (:student {name:'小张',age:20}),(:student {name:'彭莎丽',age:18})
2.匹配节点将节点删除
这样删除是将student中的条件节点删除——>会变成空白节点
match (m:student {name:"Fairy同学"}) remove m:student
MATCH (student) where id(student)=60 delete student
要彻底删除,不指定特定的图即可 delete
MATCH (n {name:"Fairy同学"}) delete n
2.复合删除
MATCH (n) WHERE id(n) = 2066 DETACH DELETE n
RETURN n
3.给指定的节点添加属性
MATCH (n:student {name:"邬雨航"}) set n.address='长沙' return n
4.给指定节点创建关系
match (n:student {name:'邬雨航'}),(m:student{name:'Fairy同学'})
create (n)-[r:`别名`{relation:'别名'}]->(m) return r
MATCH (n:student {name:'邬雨航'}),(m:student {name:'彭莎丽'})
create (n)-[r:`密友`{relation:'密友'}]->(m) return r
学校和学生之间的关系:
match (n:student {name:'邬雨航'}),(m:school{name:'长沙理工大学城南学院'})
create (n)-[r:`所在学校`{relation:'学校'}]->(m) return r
1.指定路径
Match (p:student) -[*]->(s:student) where id(p)=64 return s
2.给节点创建全路径
create p=(:student{name:'邬雨航'})-[:职业]->(:offer{name:'开发工程师'})<-[:职业]-
(:student {name:'小张'}) return p
3.删除指定关系
MATCH (p1:student {name:'邬雨航'})-[r:`所在学校`]-(p2:student {name:'彭莎丽'})
DELETE r
4.查询某个节点的所有关系
1.第一种,单向:
MATCH (n:student {name:'邬雨航'})-->(b) return n,b
2.第二种,双向:
MATCH (n:student {name:'校长'})<-->(b) return n,b
5.级联删除节点的关系
//1.指定条件
MATCH (r) WHERE id(r) = 60 DETACH DELETE r
//2.全删除
MATCH (r) DETACH DELETE r
5.添加唯一约束
添加name的唯一约束
CREATE CONSTRAINT ON (cc:student)
ASSERT cc.name IS UNIQUE
6.常见函数
1.统计节点数count
match (n:student) return count(n)
2.MAX()和SUM()函数的使用
MATCH (s:student) RETURN MAX(s.age),SUM(s.age)
```![在这里插入图片描述](https://img-blog.csdnimg.cn/6c4e0d75fb5e44dba274f2231c6b5659.png)