//Table names
public static final String TABLE_SUBJECTS = "SUBJECTS";
public static final String TABLE_TIMETABLE = "TIMETABLE";
public static final String TABLE_ATTENDANCE = "ATTENDANCE";
//Column names
public static final String COLUMN_SUBJECTS_SUBJECT = "SUBJECT"; //Subjects
public static final String COLUMN_TIMETABLE_SUBJECT = "SUBJECT"; //Timetable
public static final String COLUMN_TIMETABLE_PERIOD = "PERIOD";
public static final String COLUMN_TIMETABLE_DAY = "DAY";
public static final String COLUMN_ATTENDANCE_SUBJECT = "SUBJECT";
//Attendance
public static final String COLUMN_ATTENDANCE_ATTENDED = "ATTENDED";
public static final String COLUMN_ATTENDANCE_TOTAL = "TOTAL";
public static final String COLUMN_ATTENDANCE_PERCENTAGE = "PERCENTAGE";
//Queries
private static final String SQL_CREATE_TABLE_TIMETABLE = "create table " + TABLE_TIMETABLE + "(" +
COLUMN_TIMETABLE_SUBJECT + " text, " +
COLUMN_TIMETABLE_PERIOD + " integer, " +
COLUMN_TIMETABLE_DAY + " text, " +
"PRIMARY KEY " + "(" +
COLUMN_TIMETABLE_PERIOD + "," +
COLUMN_TIMETABLE_DAY + "), " +
"FOREIGN KEY " + "(" + COLUMN_TIMETABLE_SUBJECT + ") " +
"REFERENCES " + TABLE_SUBJECTS + " (" + COLUMN_SUBJECTS_SUBJECT +
")" + ");";
private static final String SQL_CREATE_TABLE_ATTENDANCE = "create table " + TABLE_ATTENDANCE + "(" +
COLUMN_ATTENDANCE_SUBJECT + " text, " +
COLUMN_ATTENDANCE_ATTENDED + " integer, " +
COLUMN_ATTENDANCE_TOTAL + " integer, " +
COLUMN_ATTENDANCE_PERCENTAGE + " integer, " +
"PRIMARY KEY " + "(" + COLUMN_ATTENDANCE_SUBJECT + "), " +
"FORIEGN KEY " + "(" + COLUMN_ATTENDANCE_SUBJECT + ") " +
"REFERENCES " + TABLE_SUBJECTS + " (" + COLUMN_SUBJECTS_SUBJECT + ")" +
");";
所以,我正在尝试使用SQLite编写一个Android应用程序。我在尝试创建“ATTENDANCE”表时遇到了问题。 它说“FOREIGN”附近的语法错误。现在,我没有得到这个,因为你可以看到我已经成功地创建了“TIMETABLE”表,并且在“ATTENDANCE”表中也遵循了或多或少相同的语法。 我甚至试过评论外键。仅使用主键约束它可以正常工作,但是当我将它与外键约束结合时,错误再次出现。如果我注释掉主键部分,仅使用外键约束,那么它会在“SUBJECT”附近显示“语法错误”。所以,请帮忙。
答案 0 :(得分:2)
您的SQL_CREATE_TABLE_ATTENDANCE
字符串中有拼写错误。 FOREIGN KEY
编写错误FORIEGN KEY