0

I have created 2 tables and I want these 2 to have a relationship together. I am going to create more tables and they too should have a relationship, but, I do not know how to achieve it. Thanks in advance.

private static final String DATABASE_CREATE = "create table " 
            + CustomerTable
            + "(" 
            + COLUMN_ID + " integer primary key autoincrement, " 
            + COLUMN_CATEGORY + " text not null, " 
            + COLUMN_SUMMARY + " text not null," 
            + COLUMN_DESCRIPTION
            + " text not null" 
            + ");";

    private static final String DATABASE_TABLE = "create table " 
            + OrderTable
            + "("
            + COLUMN_ORDER_ID + " integer primary key autoincrement, "
            + COLUMN_FOOD+ text not null," , " 
            + COLUMN_BOOK + " text not null, " 
            + COLUMN_CAR + " text not null," 
            + ");";
VenomVendor
  • 15,064
  • 13
  • 65
  • 96
Djkgotso
  • 130
  • 2
  • 4
  • 15

1 Answers1

0

It depends what version of Android you're targeting. Foreign keys are the mechanism for relating tables, but these weren't introduced into SQlite until v3.6.19 which appeared in Android 2.2 according to this: https://stackoverflow.com/a/4377116/201113

If your app is going to run on devices running < Android 2.2, you'll need to use triggers. I used this website to create some triggeres, http://rcs-comp.com/site/index.php/view/Utilities-SQLite_foreign_key_trigger_generator. You just execute these when your database is created.

Community
  • 1
  • 1
barry
  • 4,037
  • 6
  • 41
  • 68