如何设置列上sqlite的唯一索引如何设置、索引、sqlite

2023-09-04 11:01:55 作者:花已落゛情已灭

我有3列(_id,列1,列2)_id列已被设置为自动增量

I have 3 columns (_id, column1, column2) _id column has been set as autoincrement

在数据库中有一些重复的记录,所以我想prevent重复的记录与列1设置为唯一索引。我如何设置一个列上sqlite的唯一索引?或者,我怎么prevent重复的记录?

In database there are some duplicate records, so I want to prevent duplicate records with setting column1 as unique indexer. How do I set a column as unique indexer on sqlite? Or how do I prevent duplicate records?

推荐答案

没有魔法,只是SQL:

No magic, just SQL:

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

_id不会重复以任何方式,因为它是主键,COLUMN1也不是因为它是独一无二的。

_id will not be duplicate in any way because it is primary key, column1 neither because it is unique.