Create trigger using Room Database(Room Persistence Library) Create trigger using Room Database(Room Persistence Library) database database

Create trigger using Room Database(Room Persistence Library)


Call getOpenHelper() on your RoomDatabase. This gives you a SupportSQLiteOpenHelper, which has an API reminiscent of SQLiteOpenHelper. On there, call getWritableDatabase() to get a SupportSQLiteDatabase, and on there use execSQL() to execute your SQL statements. A RoomDatabase.Callback is one place to execute this sort of SQL, as AdamMc331 illustrates in this Kotlin snippet.

IOW, Room does not really help with this scenario, but you can always work with the lower-level database API for cases like this one.