# 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)Recommended prerequisites

*   You should complete [Lesson 3](../3-reading-data/index.md) before starting this lesson.
    

## [](#_lesson_contents)Lesson contents

[Lesson 4.1: Inserting simple data](4.1-inserting-simple-data/index.md)

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

[Lesson 4.2: Inserting polymorphic data](4.2-inserting-polymorphic-data/index.md)

Learn how to insert data with polymorphic queries.

[Lesson 4.3: Deleting data](4.3-deleting-data/index.md)

Learn how to delete entities, relations, and attributes.

[Lesson 4.4: Updating data](4.4-updating-data/index.md)

Learn how to update the attributes of entities and relations.

[Lesson 4.5: Data validation](4.5-data-validation/index.md)

Learn about how new data is validated against the schema.

## [](#_running_examples)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** 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.

## [](#_typeql_keywords_introduced)TypeQL keywords introduced

*   `insert`
    
*   `delete`
    

[Summary](../3-reading-data/summary/index.md) [Inserting simple data](4.1-inserting-simple-data/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/academy/modules/ROOT/pages/4-writing-data/index.adoc) Edit this page on GitHub.