0Pricing
Neo4j Graph Database Fundamentals · Pelajaran

Membuat Data dengan Cypher CREATE

Pelajari cara menggunakan klausa CREATE untuk menambahkan node dan relasi baru ke basis data graf Neo4j Anda.

Membuat Data dengan Cypher CREATE adalah pelajaran Neo4j Graph Database Fundamentals gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Neo4j Graph Database Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Neo4j Graph Database Fundamentals mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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!

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Membuat Data dengan Cypher CREATE” gratis?

Ya — teks lengkap “Membuat Data dengan Cypher CREATE” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Neo4j Graph Database Fundamentals, upgrade ke CoddyKit PRO. Kursus Neo4j Graph Database Fundamentals mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Membuat Data dengan Cypher CREATE”?

Pelajari cara menggunakan klausa CREATE untuk menambahkan node dan relasi baru ke basis data graf Neo4j Anda. Kamu berlatih Neo4j Graph Database Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Neo4j Graph Database Fundamentals?

Tidak diperlukan pengalaman sebelumnya. Neo4j Graph Database Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “Membuat Data dengan Cypher CREATE” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Neo4j Graph Database Fundamentals ini?

Ya. Setiap pelajaran Neo4j Graph Database Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Node, Relasi, dan Properti
  2. Membuat Data dengan Cypher CREATE
  3. Mencocokkan Pola dengan Cypher MATCH
  4. Mengembalikan dan Membentuk Hasil dengan RETURN
← Kembali ke Neo4j Graph Database Fundamentals