2011-03-16 30 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