0
0
Android Kotlinmobile~5 mins

Room queries (Insert, Update, Delete, Select) in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@Delete
B@Update
C@Insert
D@Query
What does the @Update annotation require to identify which row to update?
AColumn name
BRow number
CTable name
DPrimary key in the entity
How do you delete a record using Room?
AUse @Delete with the entity to remove
BUse @Insert with null values
CUse @Update with empty fields
DUse @Query with SELECT statement
Which SQL statement is used inside @Query to get all rows from a table named 'users'?
ASELECT * FROM users
BDELETE FROM users
CUPDATE users SET
DINSERT INTO users
What type of value does a @Query method that selects multiple rows usually return?
ASingle entity
BList of entities
CBoolean
DInteger
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.