neo4j sql语法

语法名发音

neo4j 语法为 Cypher【ˈsaɪfər】

基础概念

点(行记录)
边(关系表)
属性(字段)
标签(表)

关键字

查询 match start
条件 where
修改 set
移除 remove
删除 delete
返回值 return
索引 index

查询

match
match (n:Phone)-[r:Friend]->(m:Phone) return n,m;//查询所有手机号和关系
match (n) return n;//查询全部
match (n:Phone)<-[r:Friend]-(m:Phone) where n.number=13116604681return n,m;//查询单个手机号关系
match (n) where id(n)=1 return n; //查询单个手机号
match (n) where n.number starts with "131" return n;
match (n) where n.number ends with "681" return n;
match (n) where n.number contains "1660" return n;

start
start n=node(2) ,m=node(3) return m,n;

新增

# 新增节点
 create (n:Device{number:”16116604686”}) return n;
#新增边 
start n=node(x),m=node(y) create (n)-[r:Friend]->(m) return n,m;
#新增标签 
start n=node(1) set n:Device return n;
#新增属性
start n=node(1) set n.test="xxxs" return n;
# 合并
MERGE (keanu:Person { name: 'Keanu Reeves' })
ON CREATE SET keanu.created = timestamp()
ON MATCH SET keanu.lastSeen = timestamp()
RETURN keanu.name, keanu.created, keanu.lastSeen
# 批量插入
UNWIND [{moble:"123"},{moble:"123"}] AS mynodes
CREATE (n:moble) SET n = mynodes

修改

#修改属性 
start n=node(1) set n.test="xxxs" return n;
#修改标签 先移除标签,再添加新标签

#修改关系 
match (n)<-[r]-(m) where id(n) =0 and id(m)=1 set r.x=1 return n,m;

删除

#移除属性 
match (n) where id(n)=1 remove n.test return n;
#移除标签 
match (n) where id(n)=1 remove n:Phone return n;
#删除关系 
match (n)<-[r]-(m) where id(n) =0 and id(m)=1 delete r return n,m;
#删除点 
match (n) where id(n)=1 delete n ;

索引

创建索引 create index on :Phone(number);
删除索引 drop index on :Phone(number);
查询索引 CALL db.indexes;

语句性能分析

explain match (n)-[]->(m) where m.number="13116604681" return n,m;
explain match (n)-[]->(m:Phone) where m.number="13116604681" return n,m;
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值