Can anyone tell me how to declare a composite primary key in Android 1.6 which includes an autoincrement _id column? I’m not sure of the syntax. I’ve ended up just enforcing it in Java when I try to add values (where registrationNumber + date has to be unique in the table):
Cursor fuelUpsCursor = getFuelUps(registrationNumber, date);
if(!fuelUpsCursor.moveToNext())
{
//add registrationNumber and date
}
I don’t really need the _id column but it can make life tricky if tables don’t have one.
Cheers,
Barry
Your question does not make much sense. Your subject line asks for a “composite foreign key”, your first sentence asks for a “composite primary key” with an
AUTOINCREMENTthat your sample code then ignores.I am going to interpret your question this way: You want an
_ID INTEGER PRIMARY KEY AUTOINCREMENTcolumn in your table to be able to use Android’sCursorAdapter, but you want to also make sure that the combination of two other columns is unique.In that case, I think that you want to use a
UNIQUEconstraint: