0

我正在制作一个表,该表有两个外键到另一个表。但是查询中仍然有错误。

这里的代码:

    //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:靠近“nilaiMatrik”:语法错误

所以我认为,我在第一个外键之后的查询中存在问题。

正确的查询应该是什么?请帮帮我

4

1 回答 1

1

这:

integer , FOREIGN 

应该

integer  FOREIGN 

使用逗号,它看起来像另一列。

这是我所拥有的:

   + BookTableMetaData.BOOK_USER_ID + " INTEGER REFERENCES "
   + UserTableMetaData.TABLE_NAME + "("
+ UserTableMetaData._ID + "),"

因此,要在您的设置中进行这项工作

MATRIK_IDKRITERIA1 + " integer REFERENCES "
+ TABLE_KRITERIA + " ("+ KRITERIA_ID +")

这可能就足够了。

于 2012-06-16T04:56:30.473 回答