Relation
// Create Relation
MATCH (a:Student),(b:Course) WHERE a.firstname = 'Rachel' AND b.id = 'C001'
CREATE (a)-[:TAKING]->(b);
MATCH (a:Student),(b:Course) WHERE a.firstname = 'Rachel' AND b.id = 'C003'
CREATE (a)-[:TAKING]->(b);
//Relation Set wrong way
MATCH (a:Student),(b:Course) WHERE a.firstname = 'Monica' AND b.id = 'C001'
CREATE (a)<-[:TAKING]-(b);
// Delete the relation
MATCH (a:Student)<-[r:TAKING]-(b:Course) WHERE a.firstname = 'Monica' AND b.id = 'C001' DELETE r;
// Recreat the relation
MATCH (a:Student),(b:Course) WHERE a.firstname = 'Monica' AND b.id = 'C001'
CREATE (a)-[:TAKING {grade:"B+"}]->(b);
//
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 101 AND b.id = 'C003' AND c.id='F003'
CREATE (c)-[:TEACHING]->(b)<-[:TAKING {grade:"A-",semester:"Spring2022"}]-(a);
// this creates duplicate link between Tony and DW
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 103 AND b.id = 'C003' AND c.id='F003'
CREATE (c)-[:TEACHING]->(b)<-[:TAKING {grade:"A-",semester:"Spring2022"}]-(a);
// This way avoids it but it also doesnt create Ross and DW
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 103 AND b.id = 'C003' AND c.id='F003' AND NOT (c)-[:TEACHING]->(b)
CREATE (c)-[:TEACHING]->(b)<-[:TAKING {grade:"A-",semester:"Spring2022"}]-(a);
MATCH (a:Student),(b:Course) WHERE a.id = 103 AND b.id = 'C003'
CREATE (a)-[:TAKING {grade:"A-"}]->(b);
MATCH (a:Student),(b:Course) WHERE a.id = 104 AND b.id = 'C004'
CREATE (a)-[:TAKING {grade:"A"}]->(b);
MATCH (a:Student),(b:Course) WHERE a.id = 105 AND b.id = 'C005'
CREATE (a)-[:TAKING {grade:"A"}]->(b);
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 106 AND b.id = 'C004' AND c.id='F001'
CREATE (a)-[:TAKING {grade:"B+"}]->(b)<-[:TEACHING]-(c);
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 106 AND b.id = 'C002' AND c.id='F002'
CREATE (a)-[:TAKING {grade:"A-"}]->(b)<-[:TEACHING]-(c);
MATCH (a:Student{firstname:"Joey"})-[r]-(b:Course{id:"C002"})
SET r.grade = "A", r.semester="Spring2022"
MATCH (a:Student{firstname:"Monica"})-[r]-(b:Course{id:"C001"})
SET r.grade = "B+"
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 101 AND b.id = 'C001' AND c.id='F001'
CREATE (c)-[:TEACHING]->(b);
MATCH (a:Student),(b:Course),(c:Faculty) WHERE a.id = 103 AND b.id = 'C003' AND c.id='F003'
CREATE (c)-[:TEACHING]->(b);
MATCH (a:Student)<-[r:TAKING]-(b:Course) WHERE a.firstname = 'Ross' AND b.id = 'C003' DELETE r;
Last updated