- 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 - CREATE Label
Neo4j CQL CREATE a Node 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 are going to discuss how to create a single label or multiple labels of a Node in this chapter. We will discuss how to create a single label to a Relationship in next chapter.
Single Label to a Node
Syntax
CREATE (<node-name>:<label-name>)
S.No. | Syntax Element | Description |
---|---|---|
1. | CREATE | It is a Neo4j CQL keyword. |
2. | <node-name> | It is a name of a Node. |
3. | <label-name> | It is a label name of a Node. |
NOTE -
We should use colon(:) operator to separate the node name and 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.
Example
This Example demonstrates how to create a Single label to "GooglePlusProfile" node.
Step 1 - Open Neo4j Data Browser
Step 2 - Type the below command on Data Browser
CREATE (google1:GooglePlusProfile)
Here google1is a node name
GooglePlusProfileis a label name for google1node
Step 3 - Click on "Execute" button and observe the results.
We can observe that one label and one node is created in the Neo4j Database.
Multiple Labels to a Node
Syntax
CREATE (<node-name>:<label-name1>:<label-name2>.....:<label-namen>)
S.No. | Syntax Element | Description |
---|---|---|
1. | CREATE | It is a Neo4j CQL keyword. |
2. | <node-name> | It is a name of a Node. |
3. | <label-name1>,<label-name2> | It is a list of label names of a Node. |
NOTE -
We should use colon(:) operator to separate the node name and label name.
We should use colon(:) operator to separate one label name to another label name.
Example
This Example demonstrates how to create multiple label names to "Cinema" node.
Multiple Label names given by our Client: Cinema,Film,Movie,Picture
Step 1 - Open Neo4j Data Browser
Step 2 - Type the below command on Data Browser
CREATE (m:Movie:Cinema:Film:Picture)
Here m is a node name
Movie, Cinema, Film, Picture are multiple label names for m node
Step 3 - Click on "Execute" button and observe the results.
Here we can observe that four labels and one node is created in the Neo4j Database.
Single Label to a Relationship
Syntax
CREATE (<node1-name>:<label1-name>)- [(<relationship-name>:<relationship-label-name>)] ->(<node2-name>:<label2-name>)
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.
Example
This Example demonstrates how to create a Label to a Relationship
Step 1 - Open Neo4J Data Browser
Step 2 - Type the below command on Data Browser
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
Step 1 - 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.