Home » Neo4j Set Clause

Neo4j Set Clause

SET clause is used to add new properties to an existing Node or Relationship. It also adds existing properties values.

Using SET command you can do the following things:

  • Set a property.
  • Remove a property.
  • Set multiple properties.
  • Set a label on a node.
  • Set multiple labels on a node.

Set a Property

SET clause is used to create a new property in a node.

Syntax:

Example:

First create a node named “Hardik” in Neo4j database.

Create a property named ?hat-trick? with value “666”.

Output:

Neo4j Set clause 1

Here you can see that a property with a key-value pair hattrick/666 is created in the node named “Hardik”.


Remove a Property

You have to pass NULL as a value to remove an existing property from a node.

Syntax:

Example:

First create a node “Dhoni” as following:

Output:

Neo4j Set clause 2

Now remove the property named POB from this node using the SET clause as following:

Output:

Neo4j Set clause 3

You can see that POB is now removed.


Set Multiple Properties

You can use SET clause to create multiple properties. You just have to specify these key value pair with commas.

Syntax:

Example:

Creates multiple properties in a node using the SET clause in Neo4j:

Output:

Neo4j Set clause 4


Set a Label on a Node

SET clause can be used to set a label to an existing node.

Syntax:

First create a node ?Ganguly? as following:

Now set a label on a node using the SET clause. This query adds the label “player” to the node Ganguly and returns it.

Output:

Neo4j Set clause 5


Set Multiple Labels on a Node

You can use SET clause to set multiple labels on a node. You have to specify labels by separating them with colons”:”.

Syntax:

Example:

First create a node named “Chetan “as following:

Use the SET clause to create multiple labels on a node.

Output:

Neo4j Set clause 6

You may also like