0

I am making one android datastorage application.In this my problem is I want to create composite primary key in sqlite table android.I want composite key for two column names. syntax:

public static final String PEN_TABLE_QUERY= " CREATE TABLE if not exists " + PEN_TABLE + "( "+ PEN_ID + " INTEGER  , " + MAIN_CATEGORY + " TEXT , " + SUB_CATEGORY + " TEXT , " + PEN_TYPE + " TEXT , " +  DESC + " TEXT , " + DATE + " TEXT PRIMARY KEY " +")";    

I want primary key for both id and date please help me

skyshine
  • 2,767
  • 7
  • 44
  • 84

1 Answers1

5

To make a composite primary key, you add a table constraint as PRIMARY KEY(column1, column2). Your current statement makes the DATE columns the primary key. The correct syntax is:

"CREATE TABLE table_name ([columns definitions...], PRIMARY KEY (column1_name, column2_name));"

Doc: http://www.sqlite.org/lang_createtable.html

Karakuri
  • 38,365
  • 12
  • 84
  • 104