Neo4j CQL - Creating A Relationship
Neo4j CQL - Creating A Relationship
Create relationships
Creating Relationships
We can create a relationship using the CREATE clause. We will specify relationship within
the square braces “[ ]” depending on the direction of the relationship it is placed between
hyphen “ - ” and arrow “ → ” as shown in the following syntax.
Syntax
Following is the syntax to create a relationship using the CREATE clause.
CREATE (node1)-[:RelationshipType]->(node2)
Example
First of all, create two nodes Ind and Dhawan in the database, as shown below.
CREATE (Dhawan)-[r:BATSMAN_OF]->(Ind)
Copy and paste the desired query in the dollar prompt and press the play button (to
execute the query) highlighted in the following screenshot.
Result
Syntax
Example
Following is a sample Cypher Query which creates a relationship using the match clause.
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in
browser app of Neo4j using the URL http://localhost:7474/ as shown in the following
screenshot.
Step 2 − Copy and paste the desired query in the dollar prompt and press the play
button (to execute the query) highlighted in the following screenshot.
Result
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
Syntax
Following is the syntax to create a relationship with label and properties using the
CREATE clause.
Example
Following is a sample Cypher Query which creates a relationship with label and
properties.
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in
browser app of Neo4j using the URL http://localhost:7474/ as shown in the following
screenshot.
Step 2 − Copy and paste the desired query in the dollar prompt and press the play
button (to execute the query) highlighted in the following screenshot.
Result
On executing, you will get the following result.
Page 7 of 9
Syntax
Following is the syntax to create a path in Neo4j using the CREATE clause.
Example
To execute the above query, carry out the following steps −
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in
browser app of Neo4j using the URL http://localhost:7474/ as shown in the following
screenshot.
Page 8 of 9
Step 2 − Copy and paste the desired query in the dollar prompt and press the play
button (to execute the query) highlighted in the following screenshot.
Result