Nightpoison
Newbie
Hello.
I'm looking for some direction on creating a table that has uses UNIQUE constraints. When adding new rows to my database, I want to make sure I don't add a duplicate value. However, I need to check that the combination of two columns is unique.
for example the column names are as follows.
KEY_RECORD will repeat over 7 rows, with a the KEY_FILE iterating 1-7 such as
currently I'm creating my DB using sqliteOpenHelper. I do the following.
I know if I add the keyword UNIQUE I can make any of the columns unique.
But how do I do it so that a combination of the two columns must be unique in order to add.
I'm looking for some direction on creating a table that has uses UNIQUE constraints. When adding new rows to my database, I want to make sure I don't add a duplicate value. However, I need to check that the combination of two columns is unique.
for example the column names are as follows.
Code:
KEY_RECORD KEY_FILE KEY_TIME KEY_TEMP KEY_CONC
KEY_RECORD will repeat over 7 rows, with a the KEY_FILE iterating 1-7 such as
Code:
KEY_RECORD KEY_FILE KEY_TIME KEY_TEMP KEY_CONC
0001 1
0001 2
...
0001 7
0002 1
0002 2
....
currently I'm creating my DB using sqliteOpenHelper. I do the following.
Java:
private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_RECORDS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_RECORD + " TEXT," + KEY_FILE + " TEXT," + KEY_TIME + " TEXT," + KEY_TEMP + " TEXT," + KEY_CONC + " TEXT" + " )";
...
@Override
public void onCreate (SQLiteDatabase db)
{
db.execSQL(TABLE_CREATE);
db.close();
}
I know if I add the keyword UNIQUE I can make any of the columns unique.
Java:
private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_RECORDS + "(... + " TEXT UNIQUE," + KEY_FILE + ..." + " )"
But how do I do it so that a combination of the two columns must be unique in order to add.