Create Relationship
CREATE statement is used to create relationship between nodes. These relationships define direction, type and form patterns of the data.
It defines mainly three things:
- Creating Relationships
- Creating Relationships between existing nodes
- Creating relationships with label and properties
Creating Relationship
While creating a relationship, relationship should be specified within square braces “[ ]”, depending on the direction of the relationship it is placed between hyphen ” – ” and arrow ” ? ” as shown in the following syntax.
Syntax:
Example
Let’s create two nodes “Raul” and “It” first and then specify the relationship between them.
Now create a relationship “PLAYER_OF between these two nodes as ?
Output:
You can also see it in tabular or text form:
You can also download (export) the graph in which format you want to save it. Click on the download button, see the example:
Create a Relationship between existing Nodes
MATCH statement is used to create relationship between the existing Nodes.
Syntax:
Example
Create a relationship using MATCH statement.
Output:
Create a Relationship with Label and Properties
CREATE statement is used to create a relationship with label and properties.
Syntax:
Example:
Let’s take an example to create a relationship for a node with label and properties using the CREATE statement.
First create a node “Kohli”, having multiple labels
Then create some properties with the same node:
Create another node “Ind”:
Now create a relationship with label and properties:
Creating a complete path
In Neo4j, CREATE statement is used to create a path. A path is formed using continuous relationship.
Syntax:
Example:
First create a node3 name “Champions_Trophy” to do further operations.
Now execute the following code: