Neo4j Create NodesNode is a data or record in a graph database. In Neo4j, the CREATE statement is used to create a node. You can create the following things by using CREATE statement:
Create a Single NodeTo create a single node in Neo4j, specify the name of the node along with CREATE statement. Syntax: Note: You can add or ignore semicolon (;). It is optional.Example1: Open the localhost on the browser: http://localhost:7474/browser/ and use the following code: Output: You can see that a node is created. VerificationExecute the following code to verify the creation of the node type: Output: Create Multiple NodesTo create multiple nodes in Neo4j, use CREATE statement with the name of nodes separated by a comma. Syntax: Example2: Let's create 2 nodes: primary_node and secondary_node. VerificationOutput: Note: It is displaying 3 nodes because we have created a node already in example1.Create a node with a labelIn Neo4j, a label is used to classify the nodes using labels. CREATE statement is used to create a label for a node in Neo4j. Syntax: Example3: Let's create a node "Kalam" with a label "scientist". Output: VerificationOutput: Create a Node with Multiple LabelsTo create multiple labels with a single node, you have to specify the labels for the node by separating them with a colon " : ". Syntax: Example: Create a node "Kalam" with label "person", "president", and "scientist". Output: VerificationCreate Node with PropertiesIn Neo4j, properties are the key-value pairs which are used by nodes to store data. CREATE statement is used to create node with properties, you just have to specify these properties separated by commas within the curly braces "{ }". Syntax: Example: Let's create a node "Ajeet", having the following properties: Output: VerificationReturning the created nodeMATCH (n) RETURN n command is used to view the created nodes. This query returns all the existing nodes in the database. But if you want to return the newly created node use the RETURN command with CREATE command: Syntax: Example: Create a node "Sonoo" with following properties and return that node. Output: Next TopicNeo4j Create Relationships |