- Neo4j Tutorial
- Neo4j - Home
- Neo4j - Overview
- Neo4j - Data Model
- Neo4j - Environment Setup
- Neo4j - Building Blocks
- Neo4j CQL Write Clauses
- Neo4j - Merge Command
- Neo4j - Set Clause
- Neo4j - Delete Clause
- Neo4j - Remove Clause
- Neo4j - Foreach Clause
- Neo4j CQL Read Clause
- Neo4j - Match Clause
- Neo4j - Optional Match Clause
- Neo4j - Where Clause
- Neo4j - Count Function
- Neo4j CQL General Clauses
- Neo4j - Return Clause
- Neo4j - Order By Clause
- Neo4j - Limit Clause
- Neo4j - Skip Clause
- Neo4j - With Clause
- Neo4j - Unwind Clause
- Neo4j CQL Functions
- Neo4j - String Functions
- Neo4j - Aggregation Function
- Neo4j CQL Admin
- Neo4j - Backup & Restore
- Neo4j - Index
- Neo4j - Create Unique Constraint
- Neo4j - Drop Unique
- Neo4j Useful Resources
- Neo4j - Quick Guide
- Neo4j - Useful Resources
- Neo4j - Discussion
Relationship without Properties with New Nodes
In this scenario, we are going to create two Nodes and Relationship without properties at a time. That means, our Neo4J Database does NOT have these two nodes.
We use CQL CREATE command to create both end Nodes and new Relationship between them at a time.
Syntax
CREATE (<node1-label-name>:<node1-name>)- [<relationship-label-name>:<relationship-name>]-> (<node1-label-name>:<node1-name>) RETURN <relationship-label-name>
Syntax Description
S.No. | Syntax Element | Description |
---|---|---|
1. | CREATE,RETURN | They are Neo4J CQL keywords. |
2. | <node1-name> | It is a name of "From Node" used to create a Relationship. |
3. | <node1-label-name> | It is a label name of "From Node" used to create a Relationship. |
4. | <node2-name> | It is a name of "To Node" used to create a Relationship. |
5. | <node2-label-name> | It is a label name of "To Node" used to create a Relationship. |
6. | <relationship-name> | It is a name of a Relationship. |
7. | <relationship-label-name> | It is a label name of a Relationship. |
NOTE -
In this syntax, RETURN clause is optional. If we want to see results immediately, then use it. Otherwise we can omit this clause.
Example
This example demonstrates how to create From Node, Relationship and To Node at a time by using CQL CREATE command.
Step 1 - Open Neo4J Data Browser
Step 2 - Type the below command on Data Browser
CREATE (fb1:FaceBookProfile1)-[like:LIKES]->(fb2:FaceBookProfile2)
Here relationship name is "LIKES"
Relationship label is "like".
fb1 and FaceBookProfile1 are node name and node label name of "From Node" respectively.
fb2 and FaceBookProfile2 are node name and node label name of "To Node" respectively.
Step 3 - Click on "Execute" button and observe the results.
If we see the success message, we can observe two labels, two nodes and a relationship is created at a time.
Step 4 - Type the below command on Data Browser
MATCH (fb1:FaceBookProfile1)-[like:LIKES]->(fb2:FaceBookProfile2) RETURN like
Step 5 - Click on "Execute" button to view the results.By default, it shows the results in UI Mode.
NOTE -
If you observe the above diagram, it shows Nodes and Relationships in Bigger Font Size than previous diagrams. Because here we have used different Neo4J Data Browser Font and Color.
Please refer Neo4J Data Browser Graph Font chapter to understand how to change a Graph Font and Color
NOTE -
If we follow same steps of Example1 to create Relationship from FaceBookProfile2 to FaceBookProfile1 (That is in opposite direction), then we will have Bi-directional Relationship without Properties with new Nodes.
To Continue Learning Please Login
Login with Google