Recall & Review
beginner
What is the purpose of the @Insert annotation in Room?
The @Insert annotation tells Room to generate code that inserts an entity into the database. It simplifies adding new rows without writing SQL manually.
Click to reveal answer
beginner
How do you update an existing record in Room?
Use the @Update annotation on a DAO method. Pass the entity with updated fields, and Room will update the matching row based on the primary key.
Click to reveal answer
beginner
What does the @Delete annotation do in Room?
The @Delete annotation marks a method to remove a specific entity from the database. Room deletes the row matching the entity's primary key.
Click to reveal answer
beginner
How do you write a query to select all rows from a table in Room?
Use the @Query annotation with SQL like "SELECT * FROM tableName". The method returns a list of entities representing all rows.
Click to reveal answer
intermediate
Why is it better to use Room annotations instead of raw SQL for insert, update, and delete?
Room annotations reduce errors by generating code automatically. They ensure type safety, simplify code, and integrate well with Kotlin and LiveData.
Click to reveal answer
Which annotation is used to add a new entity to the Room database?
✗ Incorrect
The @Insert annotation is specifically for inserting new rows into the database.
What does the @Update annotation require to identify which row to update?
✗ Incorrect
Room uses the primary key in the entity to find the exact row to update.
How do you delete a record using Room?
✗ Incorrect
The @Delete annotation removes the entity matching the primary key from the database.
Which SQL statement is used inside @Query to get all rows from a table named 'users'?
✗ Incorrect
SELECT * FROM users returns all rows from the 'users' table.
What type of value does a @Query method that selects multiple rows usually return?
✗ Incorrect
Selecting multiple rows returns a List of entity objects.
Explain how to insert, update, delete, and select data using Room annotations in Kotlin.
Think about the annotations and their roles in managing database rows.
You got /4 concepts.
Describe why Room's annotations help avoid errors compared to writing raw SQL for database operations.
Consider how Room makes database work easier and safer.
You got /4 concepts.