We are femiliar with if not exits keyword when working sqllite database in Android or in web applications as well.
If not exist work with create statements, so how do we implement the same tactics in insert statement ?
Here what I found ,
Take a look at what we have
Here I got a table Entries which keep track of different entries with auto grnerated eid column. I wanna make happends only insert entries that is not exist in the table.Todo
- Create a unique index on ename column
- usere insert or ignore into statement instead of insert into
Index the colum
create unique index Entry_name_start on Entries ( ename ) ;
This will generate a intex on column ename, which means it can’t be duplicated
The new insert
insert or ignore into "Entries" ( id, ename) values ( :id, :ename) ;
It will work….
Note: I used Android Studio and plugin called DB Browser in this tutorial