SQLite的"插入或更换成"不工作 [英] SQLite "INSERT OR REPLACE INTO" not working
问题描述
我必须写在SQLite的查询,如果它的存在是为了更新记录,或将其插入如果记录不已经存在。我看过的语法INSERT或更换成
的<一个href="http://stackoverflow.com/questions/2251699/sqlite-insert-or-replace-into-vs-update-where">here.但对我来说,当我执行下面多次查询记录被复制。即如果我执行查询5倍的记录插入5次。
I have to write a query in sqlite to update the record if it exists or insert it if the record do not already exists. I have looked the syntax of INSERT OR REPLACE INTO
from here. But in my case, when I execute the query below many times the record is duplicated. i.e If I execute the query 5 times the record is inserted 5 times.
INSERT OR REPLACE INTO NICKS
(id_nick,name_nick,date_creation)
VALUES
('nabeelarif', 'Muhammad Nabeel','2012-03-04')
你有什么想法,我做错了。我的工作在Android平台,并使用 Firefox的sqlite的经理来测试我的查询
推荐答案
您需要有一个唯一索引或这些列的组合。
You need to have a unique index on one or a combination of those columns.
CREATE UNIQUE INDEX idx_something ON NICKS(id_nick,name_nick,date_creation);
这篇关于SQLite的&QUOT;插入或更换成&QUOT;不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!