嗨我对Android开发很新。 我目前有两个表,我是否需要加入这些表才能获得PK / FK匹配?
我正在尝试遵循这个设计:绿色= PK,橙色= FK
我目前有这段代码,但我认为没错。
public void onCreate(SQLiteDatabase db) {
// SQL statement to create book table
String CREATE_PLAYER_TABLE = "CREATE TABLE " + TABLE_PLAYER_INFO + "( "
+ KEY_PLAYER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_FNAME + " TEXT,"
+ KEY_LNAME + " TEXT,"
+ KEY_POSITION + " TEXT,"
+ KEY_HEIGHT + " TEXT,"
+ KEY_AGE + " TEXT,"
+ KEY_WEIGHT + " TEXT,"
+ KEY_TEAM + " TEXT,"
+ FORIGN_KEY + " TEXT,"
+ " FOREIGN KEY ("+FORIGN_KEY+") REFERENCES " + TABLE_TEAM_INFO + " ("+KEY_TEAM_ID+"))";
String CREATE_TEAM_TABLE = "CREATE TABLE " + TABLE_TEAM_INFO + "( "
+ KEY_TEAM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_TEAMNAME + " TEXT" + ")";
// create books table
db.execSQL(CREATE_PLAYER_TABLE);
db.execSQL(CREATE_TEAM_TABLE);
}
任何帮助都会很棒 感谢