Officially out now: The TypeDB 3.0 Roadmap >>

Lesson 4: Writing data

In this lesson, we’ll learn how to write data to the sample database using Insert queries, Delete queries, and Update queries. We’ll explore examples of both simple and polymorphic data writes. We’ll also see how type inference ensures that any data written is validated against the schema.

  • You should complete Lesson 3 before starting this lesson.

Lesson contents

Learn how to insert new entities, relations, and attributes.

Learn how to insert data with polymorphic queries.

Learn how to delete entities, relations, and attributes.

Learn how to update the attributes of entities and relations.

Learn about how new data is validated against the schema.

Running examples

To run an Insert, Delete, or Update query, make sure to use a data session and write transaction. The examples and exercises featured in this lesson are annotated with one of the following instructions to indicate how they should be run. Each write query should only be run once. Running write queries more than once may have unintended effects, such as inserting duplicate data.

studio run Run

Run this query without committing the transaction afterward. Write transactions will remain open for further queries, and changes will not be persisted until a commit.

studio runstudio check Run and commit

Run this query and then commit the transaction, persisting the changes to the database.

studio fail Do not run

Do not run this query, which is shown for information only. To rollback an open transaction, close it without committing.

studio run Try running

Run this query to see the error generated.

For information on how to control sessions, transactions, and queries using TypeDB Studio, refer back to Lesson 2.2.

TypeQL keywords introduced

  • insert

  • delete