how to set a column as unique indexer on Sqlite
Asked Answered
Z

1

31

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

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?

Zacatecas answered 17/12, 2011 at 10:56 Comment(0)
S
73

No magic, just SQL:

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

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

Steadman answered 17/12, 2011 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.