- 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
Neo4j CQL - Relationship Basics
Neo4j Graph Database follows the Property Graph Model to store and manages its data.
As per Property Graph Model, Relationships should be directional. Otherwise, Neo4j will throw an error message.
Based on directionality, Neo4j Relationships are categorized into two main types.
- Uni-directional Relationships
- Bi-directional Relationships
We can use Neo4j CQL CREATE command to create relationships between two nodes in the following scenarios. These scenarios are applicable for both Uni and Bi-directional relationships.
Create Relationship without Properties between two existing Nodes
Create Relationship with Properties between two existing Nodes
Create Relationship without Properties between two new Nodes
Create Relationship with Properties between two new Nodes
Create Relationship with/without Properties between two exiting Nodes with WHERE clause
NOTE -
We are going to create the relationship between Customer and CreditCard as show below
In the previous chapter, we have already created Customer and CreditCard nodes. Now we will see how to create a Relationship between them
This diagram depicts a relationship from Customer to CreditCard like
Customer → CreditCard
Here relationship is arrow mark (→)
As Neo4j CQL syntax is in human readable format. Neo4j CQL also uses similar kind of arrow mark to create a relationship between two nodes.
Each Relationship (→) contains two nodes
- From Node
- To Node
From the above diagram, Customer node is "From Node" and CreditCard Node is "To Node" to this relationship.
With respect to Nodes, they are two kinds of relationships
- Outgoing Relationship
- Incoming Relationship
From the above diagram, Relationship is a "Outgoing Relationship" to Customer Node and the same relationship is "Incoming Relationship" to CreditCard Node.
Consider the below diagram. Here we have created relationship from "CreditCard" Node to "Customer" Node.
From the above diagram, Relationship is a "Outgoing Relationship" to "CreditCard" Node and the same relationship is "Incoming Relationship" to "Customer" Node.
Consider the below diagram. Here we have created two relationships between "CreditCard" and "Customer" Nodes: One from "CreditCard" to "Customer". Another from "Customer" to "CreditCard". That means it is Bi-directional Relationship.
The following scenarios are explained here -
To Continue Learning Please Login
Login with Google