Book Image

Learning Cypher

By : Onofrio Panzarino
Book Image

Learning Cypher

By: Onofrio Panzarino

Overview of this book

Table of Contents (13 chapters)

Creating nodes and relationships

In this section, we will learn how to create nodes and relationships in our database. Let's start with the simplest example, that is, creating our first node. In the prompt, just type the following:


This command creates a node without properties or labels. It's equivalent to the following Java code:

Node n = graphDb.createNode();

The result panel now shows the result as Created 1 node, returned 0 rows in 825 ms.

The preceding command returned zero rows because we had no RETURN clause. It just created an anonymous node in the database. This node is not very useful as it is, as it can be referenced only by an ID. However, the command lets us introduce the CREATE clause. The CREATE clause takes one argument: the pattern that expresses the nodes and relationships to be created. All the patterns we learned in Chapter 1, Querying Neo4j Effectively with Pattern Matching, are supported here. Any variable used in the expression is bounded to the newly created...