Is it possible to apply primary key on the text fields in android database

as per the faq of sqlite documentation, using TEXT as a datatype for primary key should work.

i used your query and here it is, the table is created.

CREATE TABLE contacts ( email text primary key not null, name text not null);

INSERT INTO contacts VALUES ('[email protected]', 'sample')
INSERT INTO contacts VALUES ('[email protected]', 'sample')

enter image description here

enter image description here

now here is where it went wrong.

when i ran this again

INSERT INTO contacts VALUES ('[email protected]', 'sample')

nothing happened, no errors.
But it did not update the record. so i conclude data integrity is there but you don’t get any feedback about the failure.

Leave a Comment