2011-03-16 2 views
1

저는 SQLite 충돌 해결에 대해 읽었으며 한 가지 측면에 대해서는 완전히 확신하지 못했습니다.sqlite의 Conflict 절을 기반으로하는 테이블 대 쿼리를 명확하게 설명하십시오.

나는 테이블의 일환으로 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