我正在制作一个表,其中有两个外键到另一个表。但仍然在查询中出错。
这里是代码:
//inialitation attribute
public static final String TABLE_MATRIKPENDAPAT = "tableMatrikPendapat";
public static final String MATRIK_IDKRITERIA1 = "matrikIdKriteria1";
public static final String MATRIK_IDKRITERIA2 = "matrikIdKriteria2";
public static final String MATRIK_NILAI = "nilaiMatrik";
//create query
private static final String CREATE_TABLE_MATRIKPENDAPAT = "create table "
+ TABLE_MATRIKPENDAPAT + " ("
+ MATRIK_IDKRITERIA1 + " integer , FOREIGN KEY ("+ MATRIK_IDKRITERIA1 +") REFERENCES "
+ TABLE_KRITERIA + " ("+ KRITERIA_ID +"), "
+ MATRIK_IDKRITERIA2 + " integer , FOREIGN KEY ("+ MATRIK_IDKRITERIA2 +") REFERENCES "
+ TABLE_KRITERIA + " ("+ KRITERIA_ID +"), "
+ MATRIK_NILAI + " integer not null);";
错误说:
sqlite.SQLiteException: near "matrikIdKriteria2": syntax error
当我使用一个外键时,例如:
private static final String CREATE_TABLE_MATRIKPENDAPAT = "create table "
+ TABLE_MATRIKPENDAPAT + " ("
+ MATRIK_IDKRITERIA1 + " integer , FOREIGN KEY ("+ MATRIK_IDKRITERIA1 +") REFERENCES "
+ TABLE_KRITERIA + " ("+ KRITERIA_ID +"), "
+ MATRIK_NILAI + " integer not null);";
错误说:
sqlite.SQLiteException:near“nilaiMatrik”:语法错误
所以我想,我的问题出在第一个外键后的查询中。
正确的查询应该是什么? 请帮帮我们
答案 0 :(得分:1)
此:
integer , FOREIGN
应该是
integer FOREIGN
使用逗号它看起来像另一列。
这就是我所拥有的:
+ BookTableMetaData.BOOK_USER_ID + " INTEGER REFERENCES "
+ UserTableMetaData.TABLE_NAME + "("
+ UserTableMetaData._ID + "),"
所以,让你的设置工作
MATRIK_IDKRITERIA1 + " integer REFERENCES "
+ TABLE_KRITERIA + " ("+ KRITERIA_ID +")
这可能已经足够了。