- 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 Existing Nodes
In this scenario, we are going to use two existing nodes : CreditCard and Customer to create a Relationship without properties. That means, our Neo4J Database should have these two nodes.
We use CQL MATCH command to retrieve existing two nodes and CQL CREATE command to create new Relationship between them.
Syntax
MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>) CREATE (<node1-label-name>)-[<relationship-label-name>:<relationship-name>]->(<node2-label-name>) RETURN <relationship-label-name>
Syntax Description
S.No. | Syntax Element | Description |
---|---|---|
1. | MATCH,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 Uni-directional Relationship without Properties between two existing Nodes: From Customer To CreditCard.
Step 1 - Open Neo4J Data Browser
It is Neo4J Data Browser Homepage.
Before creating a Relationship From Customer To CreditCard, first check wither those Nodes are available in our Neo4J Database. If Not, Create them.
Step 2 - Verify Customer and CreditCard Nodes are available.
Type the below commands on Data Browser and verify them
MATCH (e:Customer) RETURN e
MATCH (cc:CreditCard) RETURN cc
Step 3 - Type the below command on Data Browser
MATCH (e:Customer),(cc:CreditCard) CREATE (e)-[r:DO_SHOPPING_WITH ]->(cc)
Here relationship name is "DO_SHOPPING_WITH"
Relationship label is "r".
e and Customer are node name and node label name of Customer Node respectively.
cc and CreditCard are node name and node label name of CreditCard Node respectively.
Step 4 - Click on "Execute" button and observe the results.
It shows that one new Relationship is added to the Neo4J Database
Step 5 - Type the below command on Data Browser
MATCH (e)-[r:DO_SHOPPING_WITH ]->(cc) RETURN r
Step 6 - Click on "Execute" button to view the results.By default, it shows the results in UI Mode.
Click and drag Nodes and relationships represented as Circles and arrow mark to view the diagram in the proper view
Step 7 - View the each node and relationship properties in detail.
Click on "Customer" or CreditCard node to view its properties in a separate window
Click on "DO_SHOPPING_WITH" relationship to view its property. As we have created this relationship without any properties, Properties tab is showing "No Properties" message.
NOTE -
If we follow same steps of Example1 to create Relationship from CreditCard to Customer (That is in opposite direction), then we will have Bi-directional Relationship without Properties with existing Nodes.
To Continue Learning Please Login
Login with Google