用于组合类的sqlite create语句

时间:2014-05-21 20:24:41

标签: android sql sqlite

这是我第一次尝试为android和sqlite开发,所以请在这里帮助我。

我有一张桌子:

实习: PracticalID 开始日期 结束日期, PracType, PracTopic

然后我有后续的组合表:

任务: PracticalID, TaskNo, TaskTopic, 描述和, 结果

我在android / sqlite数据库帮助程序类中的表格如下所示:

//实用

private static final String CREATE_TABLE_PRACTICAL = "CREATE TABLE " + TABLE_PRACTICAL + "(" +
        Practical_ID + " INTEGER NOT NULL PRIMARY KEY," + Start_Date + " DATE," + End_Date + 
        " DATE," + Practical_Type + " STRING," + Practical_Topic + " STRING" + ");";

//任务

private static final String CREATE_TABLE_TASKS = "CREATE TABLE " + TABLE_TASKS + 
"(" +
        Practical_ID + " INTEGER NOT NULL," + 
            Task_No + " INTEGER NOT NULL," + 
            " PRIMARY KEY" + "(" + Practical_ID + "," + Task_No + ")," +  
            Task_Topic +  " STRING," + Task_Description + " STRING," +
        Task_Outcome + " )" + "REFERENCES" + TABLE_PRACTICAL + 
            "(" Practical_ID + "));";

我的问题是我是否已正确完成此操作,或者Table_tasks中的PracticalID是否应该是外键?不想在编码过程中得到一半我已经犯了一个可怕的错误。

非常感谢!

1 个答案:

答案 0 :(得分:0)

语法不正确;列约束必须直接在列之后,并且表约束必须在所有列之后。 此外,要获得文本关联,数据类型必须包含CHAR或TEXT:

CREATE TABLE Tasks(
    Practical_ID INTEGER NOT NULL REFERENCES Practicals(PracticalID),
    TaskNo INTEGER NOT NULL,
    Task_Topic TEXT,
    Description TEXT,
    Outcomes,
    PRIMARY KEY (PracticalID, TaskNo)
);