Wednesday 21 July 2021

Neo4j: Create a relationship

Relationship used to connect two nodes in a graph. Relationships in the graph are unidirectional.

 

Create relationship

Syntax

CREATE (NODE_1)-[:RELATIONSHIP_TYPE]->(NODE_2)

 

Follow below steps to confirm the same.

 

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

http://localhost:7474/browser/

 

Step 2: Execute following queries in $ prompt to create a nodes and relationship.

CREATE (RamaKrishna:Person{name: "Rama Krishna", age: 32, city: "Bangalore", male: true})

CREATE (Suhana:Person{name: "Suhana Krishna", age: 2, city: "Bangalore", female: true})

CREATE (RamaKrishna)-[:FATHER_OF]->(Suhana)




Step 3: Get all the nodes by executing below command.

MATCH (n) RETURN n


 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment