Thursday, October 29, 2020

Neo4j - Create a Node using Cypher

CREATE (a:Artist { Name : "Strapping Young Lad" })

This Cypher statement creates a node with an Artist label. The node has a property called Name, and the value of that property is Strapping Young Lad.

The a prefix is a variable name that we provide. We could've called this anything. This variable can be useful if we need to refer to it later in the statement (which we don't in this particular case). Note that a variable is restricted to a single statement.


Displaying the Node

The CREATE statement creates the node but it doesn't display the node.

To display the node, you need to follow it up with a RETURN statement.

Let's create another node. This time it will be the name of an album. But this time we'll follow it up with a RETURN statement.


CREATE (b:Album { Name : "Heavy as a Really Heavy Thing", Released : "1995" })

RETURN b

Creating Multiple Nodes

You can create multiple nodes at once by separating each node with a comma:

CREATE (a:Album { Name: "Killers"}), (b:Album { Name: "Fear of the Dark"}) 

RETURN a,b


References:

https://www.quackit.com/neo4j/tutorial/neo4j_create_a_node_using_cypher.cfm

  



No comments:

Post a Comment