2

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

2 Answers2

3

You can try this -

CREATE TABLE tablename (
  column1, 
  column2,
  PRIMARY KEY (column1, column2)
);
Shunan
  • 3,165
  • 6
  • 28
  • 48
  • I needed the answer in a query format used in question. Otherwise your answer was available at [link](http://stackoverflow.com/questions/734689/sqlite-primary-key-on-multiple-columns) Anyway thanks – Kamran Riasat Rajput Aug 01 '16 at 13:18
2

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"