我如何创建PRIMARY和FOREIGN KEY组成的表

时间:2016-06-08 15:31:50

标签: java android sqlite foreign-keys primary-key

PRIMARY KEY TABLE_LIENS_TAG_PAGE中有2列和2个外键:

private final static String CREATE_TABLE_LIENS_TAG_PAGE =
        "CREATE TABLE " + TABLE_LIENS_TAG_PAGE + " ("
        + COL_ID_PAGE_LTP + " INTEGER NOT NULL , "
        + COL_ID_TAG_LTP + " INTEGER NOT NULL  , "
        + " PRIMARY KEY (" + COL_ID_PAGE_LTP +" "+  COL_ID_TAG_LTP +")"
        + " FOREIGN KEY ("+ COL_ID_PAGE_LTP +") REFERENCES "+ TABLE_PAGE +"("+ COL_ID_PAGE+")"
        + " FOREIGN KEY ("+ COL_ID_TAG_LTP +") REFERENCES "+ TABLE_TAG +"("+ COL_ID_TAG +"));";

见table_ Page

 public final static String TABLE_PAGE = "tb_page";
    public final static String COL_ID_PAGE = "id_page";
    public final static String COL_TITLE_PAGE = "titre_page";
    public final static String COL_DATE_PAGE = "date_page";

    private final static String CREATE_TABLE_PAGE=
            "CREATE TABLE " + TABLE_PAGE + " ("
                    + COL_ID_PAGE + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + COL_TITLE_PAGE + " TEXT NOT NULL ,"
                    + COL_DATE_PAGE + " DATE );";

和table_tag

public final static String TABLE_TAG = "tb_tag";
public final static String COL_ID_TAG = "id_tag";
public final static String COL_TEXTE_TAG = "texte_tag";

private final static String CREATE_TABLE_TAG=
        "CREATE TABLE " + TABLE_TAG + " ("
                + COL_ID_TAG + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + COL_TEXTE_TAG + " TEXT );";

0 个答案:

没有答案