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:

CREATE ()

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: ...

Get Learning Cypher now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.