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.
Recommended prerequisites
-
You should complete Lesson 3 before starting this lesson.
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.
- 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.
- Run and commit
-
Run this query and then commit the transaction, persisting the changes to the database.
- Do not run
-
Do not run this query, which is shown for information only. To rollback an open transaction, close it without committing.
- 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.