I created two sqlite tables in android
phone table
with primary key "id"
comment table
with foreign key "id"
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_BLOCKED_PHONES_TABLE =
"CREATE TABLE "+ BLOCKED_PHONES_TABLE +
" ( "+ KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL DEFAULT 1, "
+ KEY_PHONE + " TEXT UNIQUE,"
+ KEY_IS_BLOCKED+" BIT )";
db.execSQL(CREATE_BLOCKED_PHONES_TABLE);
}
and
@Override
public void onCreate(SQLiteDatabase db) {
// SQL statement to create book table
String CREATE_COMMENTS_TABLE =
"CREATE TABLE " + COMMENTS_TABLE +
" ( "+ KEY_ID+" INTEGER, "
+ KEY_COMMENT_TEXT+" TEXT, "
+ "FOREIGN KEY("+KEY_ID+") REFERENCES "+PhoneDal.BLOCKED_PHONES_TABLE+"("+KEY_ID+"))";
db.execSQL(CREATE_COMMENTS_TABLE);
}
I added some data.
including 2-3 comments to the same phone.
why does the comment table
don't refer id
as a foreign key?
otherwise it won't have ids that are missing in the phone
table.
Aucun commentaire:
Enregistrer un commentaire