【问题标题】:how to set a column as unique indexer on Sqlite如何在 Sqlite 上将列设置为唯一索引器
【发布时间】:2011-12-17 10:56:36
【问题描述】:

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

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

【问题讨论】:

    标签: android sqlite unique-index


    【解决方案1】:

    没有魔法,只有 SQL:

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

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

    【讨论】:

      猜你喜欢
      • 2022-10-01
      • 1970-01-01
      • 2010-09-16
      • 2021-09-09
      • 2016-11-30
      • 2016-10-03
      • 2022-06-30
      • 2021-04-14
      • 1970-01-01
      相关资源
      最近更新 更多