//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 + ")" +
");";
So, I'm trying to program an android app using SQLite of course. I'm running into a problem trying to create the "ATTENDANCE" table. It says "syntax error near "FOREIGN" ". Now, I don't get this because, as you can see I have created the "TIMETABLE" table successfully and in the "ATTENDANCE" table too followed more or less the same syntax. I've even tried commenting out the Foreign key. It works fine with just the primary key constraint, but when I couple it with the foreign key constraint the error shows up again. If I comment out the primary key part, with only the foreign key constraint, then it says "syntax error near "SUBJECT" ". So, please help.
Aucun commentaire:
Enregistrer un commentaire