On 10 Nov 2010, at 8:19am, Michele Pradella wrote: > Hi all, I have to INSERT a row in a DB but I have first to check if the > Key I'm inserting already exist. > Now I'm doing a "SELECT count..." first to check if the key exist and > then INSERT or UPDATE records. > Do you know if there's a better or faster way to do that?
> Perhaps with an ON CONFLICT <http://www.sqlite.org/lang_conflict.html> > resolution algorithm of INSERT or UPDATE? You could declare your key as a UNIQUE INDEX. That would make the INSERT fail if it duplicated the key of an existing record. If you know values for enough of the columns you could even declare your key as a UNIQUE INDEX and use an 'INSERT OR REPLACE'. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users