我正在尝试级联删除,以便当我从myFooTable
所有关联记录中删除记录时myFooBarLinkTable
,myBarTable
也会被删除。我当前的数据库模式尝试的简化版本如下。当我从myFooTable
关联的记录中删除一条记录时myFooBarTable
被删除;但其中的记录myBarTable
仍然存在。
public class MyDatabaseManager extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE myFooTable (fooID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"fooText1 TEXT," +
"fooText2 TEXT " +
");");
db.execSQL("CREATE TABLE myBarTable (barID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"barText1 TEXT, " +
"barText2 TEXT);" );
db.execSQL("CREATE TABLE myFooBarLinkTable (fooBarLinkID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"fooLinkID REFERENCES myFooTable(fooID) ON DELETE CASCADE, " +
"barLinkID REFERENCES myBarTable(barID) ON DELETE CASCADE);" );