2011-03-16 47 views
1

我一直在阅读关于SQLite的冲突解决方案,我并不完全确定一个方面。请澄清表和查询基于冲突条款在sqlite?

如果我有 PRIMARY KEY ON CONFLICT IGNORE作为表的一部分,我还需要投入INSERT OR IGNORE上插入查询有它忽略冲突,还是会从表定义上回暖?

我读的东西说了一些关于表定义只影响整个表上的操作,但我不确定这是否合理。

回答

2

在问这个问题之前,您是否考虑过测试一下?

sqlite> create table test (id integer primary key on conflict ignore); 
sqlite> insert into test values (1); 
sqlite> insert into test values (1); 
sqlite> insert into test values (1); 
sqlite> insert into test values (1); 
sqlite> select * from test; 
1 

sqlite> drop table test; 
sqlite> create table test (id integer primary key); 
sqlite> insert into test values (1); 
sqlite> insert into test values (1); 
Error: PRIMARY KEY must be unique 
sqlite> insert or ignore into test values (1); 
sqlite> insert or ignore into test values (1); 
sqlite> select * from test; 
1