Android: creating SQLite database with relation

I am trying to create an application that requires a SQLite database with two tables with a one to one relationship.

Basically the first table will allow the user to create an employee, when they click on an employee, it will move them to the second activity which will allow users to add multiple phone numbers for that employee, which is stored in the second table.

I don't know where to start with regards to creating a database with two tables and relationships. In each example, I only seem to be confronted with deinstrating a single table join.

I would appreciate any help / advice / tutorial that demonstrates such functionality.


source to share

3 answers

This tutorial allows me to successfully create a DAO class implementation:

There is no coercive relationship, although I've heard it's not very good for performance, so I stop looking.

I ended up with one DBHandler that supports DB version tracks to create / update tables. I also have a DBOpenHelper for opening / closing connections. Since I have two tables (I'll stick with Employee and Contact for the example), I have one DAO of each type, both contain a DBOpenHelper.

Hope it helps :)



A google search gave this tutorial. It demonstrates QUERIES on multiple tables using JOIN. You could probably extrapolate the QUERY concept and use them to add records. Just a thought really, but hope this helps you go in the right direction.

Similar question on SO: Android: SQLite one-to-many design

This too has no definitive answer. But again, this can help.



For those seeing this question, maybe there is a great design here:



All Articles