- 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 - CREATE a Label
Neo4j CQL CREATE Relationship Label
Label is a name or identifier to a Node or a Relationship in Neo4j Database.
We can say this Label name to a Relationship as "Relationship Type".
We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node. That means Neo4j supports only single Relationship Type between two nodes.
We can observe this Node's or Relationship's label name in CQL Data Browser in both UI Mode and Grid Mode. And also we refer it executing CQL Commands.
So far, we have created only one label to a Node or a Relationship, but we did not discuss about it's syntax much.
Neo4j CQL CREATE command is used
To create a single label to a Node
To create multiple labels to a Node
To create a single label to a Relationship
We have already discussed about how to create a single label or multiple labels of a Node in the previous chapter. Now, we will discuss how to create a label of a Relationship in this chapter.
To create a Single Label to a Relationship Syntax:
Syntax
CREATE (<node1-name>:<label1-name>)-[(<relationship-name>:<relationship-label-name>)] ->(<node2-name>:<label2-name>)
NOTE:-
In this Syntax, to accommodate space we have moved a single line into multiple lines. Please use them in a single line like CREATE (Node1)-[Relationship]->(Node2).
Syntax Description:
| S.No. | Syntax Element | Description |
|---|---|---|
| 1. | CREATE | It is a Neo4j CQL keyword. |
| 2. | <node1-name> | It is a name of a From Node. |
| 3. | <node2-name> | It is a name of a To Node. |
| 4. | <label1-name> | It is a label name of a From Node. |
| 5. | <label1-name> | It is a label name of a To Node. |
| 6. | <relationship-name> | It is a name of a Relationship. |
| 7. | <relationship-label-name> | It is a label name of a Relationship. |
NOTE:-
We should use colon(:) operator to separate the node name and label name.
We should use colon(:) operator to separate the relationship name and relationship label name.
We should use colon(:) operator to separate one label name to another label name.
Neo4j Database Server uses this name to store this node details in Database.As a Neo4j DBA or Developer, we cannot use it to access node details
Neo4j Database Server creates a label name as an alias to internal node name.As a Neo4j DBA or Developer, we should use this label name to access node details.
Example1:-
This Example demonstrates how to create a Label to a Relationship
Steps to follow:
Open Neo4j Data Browser
Type the below command on Data Browser
It is Neo4j Data Browser Homepage
CREATE (p1:Profile1)-[r1:LIKES]->(p2:Profile2)
Here p1 and Profile1 are is node name and node label name of "From Node"
p2 and Profile2 are is node name and node label name of "To Node"
r1 is a relationship name
LIKES is a relationship label name
Click on "Execute" button and observe the results.
Here We can observe that two Nodes, two labels and one Relationship is added to the Neo4j Database.