## 3.11. CREATE

The `CREATE` clause is used to create nodes and relationships.

 In the `CREATE` clause, patterns are used extensively. Read Section 2.9, “Patterns” for an introduction.

### 3.11.1. Create nodes

#### 3.11.1.1. Create single node

Creating a single node is done by issuing the following query:

Query.

``CREATE (n)``

Nothing is returned from this query, except the count of affected nodes.

Table 3.78. Result

0 rows Nodes created: 1

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n)

#### 3.11.1.2. Create multiple nodes

Creating multiple nodes is done by separating them with a comma.

Query.

``CREATE (n),(m)``

Table 3.79. Result

0 rows Nodes created: 2

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n), (m)

#### 3.11.1.3. Create a node with a label

To add a label when creating a node, use the syntax below:

Query.

``CREATE (n:Person)``

Nothing is returned from this query.

Table 3.80. Result

0 rows Nodes created: 1 Labels added: 1

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n:Person)

#### 3.11.1.4. Create a node with multiple labels

To add labels when creating a node, use the syntax below. In this case, we add two labels.

Query.

``CREATE (n:Person:Swedish)``

Nothing is returned from this query.

Table 3.81. Result

0 rows Nodes created: 1 Labels added: 2

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n:Person:Swedish)

#### 3.11.1.5. Create node and add labels and properties

When creating a new node with labels, you can add properties at the same time.

Query.

``CREATE (n:Person { name: 'Andy', title: 'Developer' })``

Nothing is returned from this query.

Table 3.82. Result

0 rows Nodes created: 1 Properties set: 2 Labels added: 1

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n:Person {name: 'Andy', title: 'Developer'})

#### 3.11.1.6. Return created node

Creating a single node is done by issuing the following query:

Query.

``````CREATE (a { name: 'Andy' })
RETURN a.name``````

The newly-created node is returned.

Table 3.83. Result
a.name

1 row Nodes created: 1 Properties set: 1

`"Andy"`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (a {name: 'Andy'}) RETURN a.name

### 3.11.2. Create relationships

#### 3.11.2.1. Create a relationship between two nodes

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them.

Query.

``````MATCH (a:Person),(b:Person)
WHERE a.name = 'A' AND b.name = 'B'
CREATE (a)-[r:RELTYPE]->(b)
RETURN type(r)``````

The created relationship is returned by the query.

Table 3.84. Result
type(r)

1 row Relationships created: 1

`"RELTYPE"`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) MATCH (a:Person), (b:Person) WHERE a.name = 'A' AND b.name = 'B' CREATE (a)-[r:RELTYPE]->(b) RETURN type(r)

#### 3.11.2.2. Create a relationship and set properties

Setting properties on relationships is done in a similar manner to how it’s done when creating nodes. Note that the values can be any expression.

Query.

``````MATCH (a:Person),(b:Person)
WHERE a.name = 'A' AND b.name = 'B'
CREATE (a)-[r:RELTYPE { name: a.name + '<->' + b.name }]->(b)
RETURN type(r), r.name``````

The newly-created relationship is returned by the example query.

Table 3.85. Result
type(r) r.name

1 row Relationships created: 1 Properties set: 1

`"RELTYPE"`

`"A<->B"`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) MATCH (a:Person), (b:Person) WHERE a.name = 'A' AND b.name = 'B' CREATE (a)-[r:RELTYPE {name: a.name + '<->' + b.name}]->(b) RETURN type(r), r.name

### 3.11.3. Create a full path

When you use `CREATE` and a pattern, all parts of the pattern that are not already in scope at this time will be created.

Query.

``````CREATE p =(andy { name:'Andy' })-[:WORKS_AT]->(neo)<-[:WORKS_AT]-(michael { name: 'Michael' })
RETURN p``````

This query creates three nodes and two relationships in one go, assigns it to a path variable, and returns it.

Table 3.86. Result
p

1 row Nodes created: 3 Relationships created: 2 Properties set: 2

`(20)-[WORKS_AT,0]->(21)<-[WORKS_AT,1]-(22)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE p = (andy {name:'Andy'})-[:WORKS_AT]->(neo)<-[:WORKS_AT]-(michael {name: 'Michael'}) RETURN p

### 3.11.4. Use parameters with `CREATE`

#### 3.11.4.1. Create node with a parameter for the properties

You can also create a graph entity from a map. All the key/value pairs in the map will be set as properties on the created relationship or node. In this case we add a `Person` label to the node as well.

Parameters.

``````{
"props" : {
"name" : "Andy",
"position" : "Developer"
}
}``````

Query.

``````CREATE (n:Person \$props)
RETURN n``````

Table 3.87. Result
n

1 row Nodes created: 1 Properties set: 2 Labels added: 1

`Node{name:"Andy",position:"Developer"}`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) CREATE (n:Person \$props) RETURN n

#### 3.11.4.2. Create multiple nodes with a parameter for their properties

By providing Cypher an array of maps, it will create a node for each map.

Parameters.

``````{
"props" : [ {
"name" : "Andy",
"position" : "Developer"
}, {
"name" : "Michael",
"position" : "Developer"
} ]
}``````

Query.

``````UNWIND \$props AS map
CREATE (n)
SET n = map``````

Table 3.88. Result

0 rows Nodes created: 2 Properties set: 4

`(empty result)`

Try this query live.  CREATE (a:Person {name: 'A'}), (b:Person {name: 'B'}) UNWIND \$props AS map CREATE (n) SET n = map