Reputation: 321
Kindly guide me. how to define both columns as primary key in this way.
sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_ATTENDEE +
" (" + COLUMN_Att_Event_ID + " TEXT PRIMARY KEY, " +
COLUMN_Att_Email + " TEXT PRIMARY KEY)");
Thanks
Upvotes: 2
Views: 5778
Reputation: 321
More than one Primary keys should be declared separately. Query is written in a format question is asked.
"CREATE TABLE IF NOT EXISTS " + TABLE_ATTENDEE +
" (" + COLUMN_Att_Event_ID + " TEXT," +
COLUMN_Att_Email + " TEXT, PRIMARY KEY(" + COLUMN_Att_Event_ID + "," + COLUMN_Att_Email + "))"
If the table has only one PRIMARY KEY then
"CREATE TABLE IF NOT EXISTS " + TABLE_ATTENDEE +
" (" + COLUMN_Att_Event_ID + " TEXT PRIMARY KEY," +
COLUMN_Att_Email + " TEXT"
Upvotes: 2
Reputation: 3264
You can try this -
CREATE TABLE tablename (
column1,
column2,
PRIMARY KEY (column1, column2)
);
Upvotes: 3