Neo4j CQL - CREATE命令
CREATE ( <node-name>:<label-name> { <Property1-name>:<Property1-Value>, ........ <Propertyn-name>:<Propertyn-Value> } ) //样例:创建两个Person实体包含name、age两个属性 CREATE (WLC:Person{name:WangLC, age:25})
CREATE (Z:Person{name:Zhang, age:35})
Neo4j CQL - MATCH命令
MATCH ( <node-name>:<label-name> ) //样例:找到Person下的name为GUAN、WangLC节点创建Teacher关系,Zhang-Teacher-WangLC MATCH (p1:Person {name:'Zhang'}), (p2:Scholar {name:'WangLC'}) CREATE (p1)-[:Teacher]->(p2)
//返回所有Person标签的节点
MATCH (p:Person) RETURN p
Neo4j CQL - RETURN命令
RETURN <node-name>.<property1-name>, ........ <node-name>.<propertyn-name> //样例:return一般用于检索实体属性,RETURN一般结合match命令使用单独不能使用 MATCH(WLC:Person) RETURN WLC.name,WLC.age; //或者直接全部显示 MATCH(WLC:Person) RETURN WLC;
Neo4j CQL - 创建关系、检索关系命令
MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>) CREATE (<node1-label-name>)-[<relationship-label-name>:<relationship-name> {<define-properties-list>}]->(<node2-label-name>) RETURN <relationship-label-name> //样例:创建Zhang-Teacher-WangLC关系并且包含在2016年-2019年属性信息,单项关系 MATCH (p1:Person{name:'Zhang'}),(p2:Person{name:'WangLC'}) CREATE (p1)-[t:Teacher{date:"2016.9-2019.6"}]->(p2) RETURN r; //检索关系 MATCH (p1:Person{name:'Zhang'})-[t:Teacher]->(p2:Person{name:'WangLC'}) return t;
Neo4j CQL -WHERE 条件语句
WHERE <condition> <boolean-operator> <condition> boolean-operator:OR|AND|XOR|NOT <condition>:<property-name> <comparison-operator> <value> comparison-operator:<>|>|<|>=|<=|= //样例 match(p:Person)where p.name="WangLC" or p.name="Zhang" return p;
Neo4j CQL - DELETE 删除语句
DELETE <node-name-list> //删除(永久删除)查询到的节点 DELETE <node1-name>,<node2-name>,<relationship-name> //删除查询到的节点以及关系 //样例 删除节点 MATCH(p1:Person(name:"Zhang")) DELETE p1; //删除 节点、关系 MATCH(p1:Person{name:"Zhang"})-[r:Teacher]->(p2:Person{name:"WangLC"}) DELETE p1,p2,r
Neo4j CQL - REMOVE 删除语句
REMOVE <property-name-list> //remove命令用于删除节点属性,节点标签 //样例 由于给person节点添加了错误的pages属性因此要删除掉Person节点的pages属性 match(p:Person)remove p.pages return p;
Neo4j CQL - SET 添加属性语句
SET <property-name-list> //样例 给person添加birthday属性 match(p:Person{name:'Zhang'}) set p.birthday='20181210' return p;
Neo4j CQL - Sorting 排序语句
ORDER BY <property-name-list> [DESC] //样例 按照出生年从大到小排序 match(p:Person)return p order by p.born desc; // 按照出生年从小到大排序 match(p:Person)return p order by p.born;