Tuesday, 27 July 2021

Neo4j: Add label, properties to a relationship

Syntax

CREATE (node1)-[label:Rel_Type {key1:value1, key2:value2, . . . n}]-> (node2)

Example

CREATE (RamaKrishna:Person{name: "Rama Krishna", age: 32, city: "Bangalore", male: true})
CREATE (MuraliKrishna:Person{name: "Murali Krishna", age: 34, city: "Hyderabad", male: true})
CREATE (RamaKrishna)-[c:COLLEAGUES {since: "5 yrs", organization: "yahoo"}]->(MuraliKrishna)


Step 1: Open neo4j browser by hitting following url in browser.

http://localhost:7474/browser/

 




Step 2: Execute below queries to create nodes and relationship among them.


 

CREATE (RamaKrishna:Person{name: "Rama Krishna", age: 32, city: "Bangalore", male: true})
CREATE (MuraliKrishna:Person{name: "Murali Krishna", age: 34, city: "Hyderabad", male: true})
CREATE (RamaKrishna)-[c:COLLEAGUES {since: "5 yrs", organization: "yahoo"}]->(MuraliKrishna)

 


 

Step 3: Get the node to verify.

MATCH (n) RETURN n


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment