0Pricing
Neo4j Graph Database Fundamentals · Lección

Creación de datos con Cypher CREATE

Aprenda a utilizar la cláusula CREATE para añadir nuevos nodos y relaciones a su base de datos de grafos Neo4j.

Creación de datos con Cypher CREATE es una lección gratuita de Neo4j Graph Database Fundamentals en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Neo4j Graph Database Fundamentals, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Neo4j Graph Database Fundamentals incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Welcome to Cypher CREATE!

In this lesson, you'll learn how to add new data to your Neo4j graph database using the CREATE clause in Cypher, the query language for Neo4j.

We'll cover creating individual nodes, adding properties, and defining relationships between them. Let's get started!

Creating Your First Node

The simplest way to add a node is with CREATE followed by parentheses (). Inside the parentheses, you can give your node a variable name (like n) for later reference in the same query.

Try running this basic example:

CREATE (n)

Adding Labels to Nodes

Nodes usually represent real-world entities, like a 'Person' or a 'Movie'. We use labels to categorize nodes. Labels are defined after the node variable using a colon :.

It's good practice to always use labels for better organization and querying.

CREATE (p:Person)

Nodes with Properties

Nodes often have attributes that describe them. These are called properties. Properties are key-value pairs enclosed in curly braces {} after the label.

  • Keys are strings (like name).
  • Values can be strings, numbers, booleans, or lists.
CREATE (m:Movie {
  title: 'The Matrix',
  releaseYear: 1999
})

Creating Multiple Nodes

You can create several nodes in a single CREATE statement by separating them with a comma ,. This is efficient when adding related data.

Here, we're creating two different types of nodes at once:

CREATE (a:Actor {name: 'Keanu Reeves'}),
       (d:Director {name: 'Lana Wachowski'})

Introducing Relationships

Relationships define how nodes are connected. They are directional and always connect two nodes. Their syntax looks like an arrow ()-[]->().

  • () for nodes.
  • -[]-> for a directed relationship.
  • -[]- for an undirected relationship (less common).

Creating Relationships Between Existing Nodes

To create a relationship between nodes that already exist, you first need to MATCH them. Then, you can use CREATE to define the relationship.

Relationships also have a type (e.g., ACTED_IN) and can have properties.

MATCH (a:Actor {name: 'Keanu Reeves'})
MATCH (m:Movie {title: 'The Matrix'})
CREATE (a)-[:ACTED_IN]->(m)

Relationships with Properties

Just like nodes, relationships can also have properties. These properties describe the relationship itself, not the nodes it connects.

For example, an ACTED_IN relationship might have a role property.

MATCH (a:Actor {name: 'Keanu Reeves'})
MATCH (m:Movie {title: 'The Matrix'})
CREATE (a)-[:ACTED_IN {role: 'Neo'}]->(m)

Creating Nodes and Relationships Together

One of the most powerful features of CREATE is the ability to define new nodes and their relationships in a single statement. This helps build complex graph patterns efficiently.

Here, we create a new 'Person' and a new 'City', connecting them with a LIVES_IN relationship.

CREATE (p:Person {name: 'Samantha'})
       -[:LIVES_IN]->
       (c:City {name: 'London', country: 'UK'})

Putting It All Together

Let's combine what we've learned to build a small graph for a fictional 'Project' and 'Team' members:

  • Create a Project node.
  • Create two Person nodes.
  • Connect the Persons to the Project with WORKS_ON relationships, each with a role property.
CREATE (p:Project {name: 'CoddyKit App', budget: 50000})
CREATE (dev:Person {name: 'Alex', email: 'alex@example.com'})
CREATE (qa:Person {name: 'Jamie', email: 'jamie@example.com'})
CREATE (dev)-[:WORKS_ON {role: 'Developer'}]->(p)
CREATE (qa)-[:WORKS_ON {role: 'QA Engineer'}]->(p)

Quick Check on CREATE

Which of the following Cypher statements correctly creates a new node labeled Product with a name property of 'Laptop' and a price of 1200?

Recap & Next Steps

Great job! You've learned the fundamentals of creating data in Neo4j using the Cypher CREATE clause.

  • You can create nodes with labels and properties.
  • You can define directional relationships between nodes.
  • You can even create nodes and relationships in a single statement.

Next, you'll learn how to find and retrieve this data using the MATCH clause!

Preguntas frecuentes

¿La lección «Creación de datos con Cypher CREATE» es gratis?

Sí — el texto completo de «Creación de datos con Cypher CREATE» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Neo4j Graph Database Fundamentals, actualiza a CoddyKit PRO. El curso de Neo4j Graph Database Fundamentals incluye 4 lecciones en total.

¿Qué aprenderé en «Creación de datos con Cypher CREATE»?

Aprenda a utilizar la cláusula CREATE para añadir nuevos nodos y relaciones a su base de datos de grafos Neo4j. Practicas Neo4j Graph Database Fundamentals con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Neo4j Graph Database Fundamentals?

No se requiere experiencia previa. Neo4j Graph Database Fundamentals en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Creación de datos con Cypher CREATE»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Neo4j Graph Database Fundamentals?

Sí. Cada lección de Neo4j Graph Database Fundamentals incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Nodos, relaciones y propiedades
  2. Creación de datos con Cypher CREATE
  3. Coincidencia de patrones con Cypher MATCH
  4. Devolución y estructuración de resultados con RETURN
← Volver a Neo4j Graph Database Fundamentals