2011-12-17 13 views
30

我有3列(_id,列1,列2)_id柱已经被设置为自动增量如何设置列独特的索引上sqlite的

在数据库中有一些重复的记录,所以我想,以防止重复记录将column1设置为唯一索引器。如何在sqlite上将列设置为唯一索引器?或者我如何防止重复记录?

回答

66

没有魔法,只是SQL:以任何方式

create table yourtablename (_id integer primary key autoincrement, column1 text not null unique, column2 text); 

_id不会是重复的,因为它是主键,COLUMN1既不是因为它是独一无二的。

+2

请参阅http://www.tutorialspoint.com/sqlite/sqlite_constraints.htm – Aliti 2014-05-18 09:54:37