我创建了2个表,我希望这两个表有一个关系。我将创建更多的表,他们也应该有一个关系,但是,我不知道如何实现它。提前谢谢。
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,"
+ ");";
答案 0 :(得分:0)
这取决于您定位的Android版本。外键是用于关联表的机制,但直到v3.6.19才出现在SQlite中,它出现在Android 2.2中,根据:https://stackoverflow.com/a/4377116/201113
如果您的应用将在运行<的设备上运行Android 2.2,你需要使用触发器。我用这个网站创建了一些触发器,http://rcs-comp.com/site/index.php/view/Utilities-SQLite_foreign_key_trigger_generator。您只需在创建数据库时执行这些操作。