开发者

Multi-table database in Android app

开发者 https://www.devze.com 2023-04-07 11:44 出处:网络
I am trying to develop android app that has more than one table. Doubts:- Can I have foreign keys? Is it advisable in terms of performance?

I am trying to develop android app that has more than one table.

Doubts:-

  1. Can I have foreign keys? Is it advisable in terms of performance?

  2. Which part of code should take care of create and upgr开发者_如何学JAVAade of all tables? Let say I have tables for 'Cart' and 'Item'. Cart HAS Items. How should I code db adapter for these two entities.


Can I have foreign keys? Is it advisable in terms of performance?

Yes, and you should if your business logic requires them. Don't even think about "optimizing them away" before you have thoroughly profiled your app and are 1000% percent sure it's foreign keys slowing down your app. You don't want your app to deliver garbage results faster, you want it to deliver the correct results.

Which part of code should take care of create and upgrade of all tables? Let say I have tables for 'Cart' and 'Item'. Cart HAS Items. How should I code db adapter for these two entities.

Creating and upgrading the database schema is the task of a class you extend from SQLiteOpenHelper

I highly suggest you work through the Android database tutorial and check out a book on Android for more details on this topic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号