Open In App

Neo4j | Naming rules and recommendations

Last Updated : 20 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

There is few rules for naming, to naming of node labels, relationship types, property names and variables have to follow some rules unless error will occurred. Rules for Naming:

  • To name node labels, relation types, property names also variables names should start with the alphabetic letter. This could be non-English character also. If the numeric character is required to name anything mentioned above then you can use the backticks for escaping the non-alphabetic character like `^n`.
  • Naming can contains the number but not in first place like 1Geeks is not allowed. You can use that as Geeks1 or Geek1s. But if you have to put a numeric at the begin then similarly use the backticks like `1Geeks` that backticks will skip the 1 and others characters behave as it should be.
  • The naming in Neo4j can not contains any kind of special symbols for naming. But the underscore is allowed, if the special symbol is required then use the backticks.
  • Naming could be to long 65535 (2^16 – 1) or 65534 it basically depends on the version of Neo4j.
  • Naming in Neo4j is case sensitive like :Geeks, :GEEKS and :geeks are three different labels and g and G are different variables.
  • White-space characters are acceptable all the Leading and trailing white-space characters will be removed automatically. Like MATCH ( a ) RETURN a is equivalent to MATCH (a) RETURN a. If spaces are required within a name, use backticks for escaping like `my variable has spaces`.

Rules for Scoping and namespace:

  • All the Node labels, relationship types and property names may re-use names. The following query?—?with a for the label, type and property name?—?is valid:
CREATE (a:a {a: 'a'})-[r:a]?(b:a {a: 'a'}).
  • Variables for nodes and relationships must not re-use names within the same query scope. The following query is not valid as the node and relationship both have the name
a: CREATE (a)-[a]?(b)

Recommended for naming node labels, relationship types, property names and variables:

  • Node labels: Try to use the Camel case, beginning with an upper-case character like below example.
:GeeksforGeeks rather than :geeksforgeeks
  • Relationship types: Try to use the Upper case, you can use the underscore to separate words
:Geeks_for_Geeks rather than :geeksForGeeks 

Reference:https://neo4j.com/docs/cypher-manual/current/syntax/naming/


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads