1.这种写法无关主键
Insert or Ignore into tableName(col1,col2......) select '{0}','{1}'...
where not exists
(select col1,col2...... from tableName where col1='{0}' and col2='{1}' ....)
2.下面这种写法field1为主键
假设你的表叫:yourtable,其有二个字段:field1, field2(假设都是 int 型,field1 为主键)
如果不存在就插入,存在就忽略的方式,用 insert or ignore:
INSERT OR IGNORE INTO yourtable (field1,field2) VALUES(1,2)
或者如果不存在就插入,存在就更新的方式,用 insert or replace:
INSERT OR REPLACE INTO yourtable (field1,field2) VALUES(1,2);