Search code examples
androidsqlsqliteandroid-sqlite

SQLite tables design for Android devices


I'm curious if relation table from M:M relation is needed in my case. The structure looks like this:

Table Records with fields: id, name, tags (as a string).

Table Tags with fields: id, tagName. As you see it's quite simple.

One Record could contain several Tags. On the other hand one Tag could belong to the few Records.

The case is adding/removing/modifying Records. So do I really need here some 'between' table with tag_id and record_id? Since Tags table is quite small. May be it will be better to store relation only on Tags table side?

I assume that there could be something between 50k - 150k records in Tags table. What do you think about performance of such solution? DB size will be bigger - that's known fact. DB is SQLite on Android 8+ devices.


Solution

  • I would always recommend that you use an in between table when handling many to many relationships with databases. It will prevent data duplication from occurring in the other tables, which is definitely something you should prioritize since it seems you will have quite a lot of data in your database.

    If you haven't learned about it yet, read up on database normalization