Possible Duplicate:
Is it possible to apply primary key on the text fields in android database
I have done like these getting force close.
private static final String CREATE_NEWCUSTOMER = "create table newcustomer (_id integer primary key autoincrement, "
+ "cname text primary key, date text , " + "caddress text);";
it working for integer if any have idea please help me.
You don't create primary keys like that in SQLite. I have not tested the following, but according to the documentation it should work:
private static final String CREATE_NEWCUSTOMER = "create table newcustomer (_id integer autoincrement, cname text, date text, caddress text, PRIMARY KEY(_id, cname));";
You can add primary key attribute to text without any problem. In your query above there is a major problem. You can not apply attribute 'AutoIncrement' if your Primary key is composed of more than one column.
Here is an example query that creates a table with a primary key which is comprised on two columns, one column has Integer datatype and other has text PRIMARY KEY ("col_1", "col_2")
.
CREATE TABLE "Table_Name" ("col_1" INTEGER NOT NULL , "col_2" TEXT NOT NULL , "col_3" TEXT, "col_4" VARCHAR, PRIMARY KEY ("col_1", "col_2"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With