scorpiozj
scorpiozj

Reputation: 2687

sql: insert value

I have a problem about inserting values into the table with sqlite. supposing the table:


create table test 
{ 
    KeyName varchar(50) primary key,
    KeyValue varchar (255)

};

I want to insert data like ('john', 'friend'), but I don't know whether the 'john' existed. Currently I solve it:

  1. using select * where KeyName = "john"
  2. according the result from list 1, I use insert or update;

I'd like to know whether there is better solution? thanks

Upvotes: 1

Views: 80

Answers (1)

Tal
Tal

Reputation: 154

you can use insert or replace which replaces the record if it already exists.

so you query be INSERT OR REPLACE INTO

check this link : http://www.sqlite.org/lang_conflict.html

Upvotes: 4

Related Questions