30

我有 3 列(_id、column1、column2)_id 列已设置为自动增量

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

4

1 回答 1

71

没有魔法,只有 SQL:

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

_id 不会以任何方式重复,因为它是主键,column1 也不会因为它是唯一的。

于 2011-12-17T11:00:59.093 回答