SET clause is used to create or update properties on nodes and relationships.
Setting a Single Property
To set a property on a node:Setting Multiple Properties
You can set multiple properties in a singleSET clause by separating them with commas:
Setting Properties from a Map
You can set properties using a map. There are two operators with different behaviors:Replace All Properties (=)
Replaces all existing properties with the map properties:
age and name. Any other existing properties are removed.
Merge Properties (+=)
Updates only the specified properties while keeping other existing properties:
age is updated to 33, but name and any other properties remain unchanged.
Copying Properties Between Entities
You can copy all properties from one entity to another:jim node will have exactly the same properties as the pam node (all of Jim’s original properties are replaced).
Removing Properties
To remove a property, set its value toNULL:
name property from the node entirely.
Frequently Asked Questions
What is the difference between SET n = map and SET n += map?
What is the difference between SET n = map and SET n += map?
The
= operator replaces all existing properties with the map values. The += operator merges properties, updating only specified keys while keeping other existing properties intact.Can I remove a property using SET?
Can I remove a property using SET?
Yes. Setting a property to NULL removes it:
SET n.name = NULL. This is equivalent to using the REMOVE clause.Can I copy properties from one node to another?
Can I copy properties from one node to another?
Yes. Use
MATCH (a), (b) SET a = b to copy all of bs properties to a, replacing any existing properties on a.Can I SET multiple properties at once?
Can I SET multiple properties at once?
Yes. Separate property assignments with commas:
SET n.age = 33, n.name = 'Bob'. All assignments are applied in a single operation.