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

前端 未结 2 1055
小蘑菇
小蘑菇 2020-11-30 12:22

I have created a simple table that contains the name and email id\'s of the persons. When i am giving the create query like this:

\"create table contacts (name

2条回答
  •  被撕碎了的回忆
    2020-11-30 12:49

    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 ('sample@email.com', 'sample')
    INSERT INTO contacts VALUES ('people@email.com', '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 ('sample@email.com', '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.

提交回复
热议问题