简体   繁体   English

如何删除自动增量并避免重复

[英]How to remove autoincrement and avoid duplicates

I created a user log table "id" with autoincrement primary key earlier.我之前创建了一个带有自动增量主键的用户日志表“id”。 How can I drop the autoincrement in the id field in my newer DB version?如何在较新的数据库版本中删除 id 字段中的自动增量? And I want to insert only one field to DB using only one DateTime record because now it inserts duplicates in the same DateTime records.而且我只想使用一条 DateTime 记录向 DB 插入一个字段,因为现在它会在相同的 DateTime 记录中插入重复项。

CREATE TABLE IF NOT EXISTS tbl_user_log (
    id   INTEGER  PRIMARY KEY AUTOINCREMENT,
    imei TEXT,
    date_time DATETIME,
    user_name TEXT,
    internet BOOLEAN,
    device_model TEXT,
    battery_level FLOAT,
    app_version TEXT
);
 tlog.setDatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH).format(new Date()));

To drop the autoincrement in the id field, you should try this:要在 id 字段中删除自动增量,您应该尝试以下操作:

ALTER TABLE tbl_user_log
ALTER COLUMN id
DROP AUTOINCREMENT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM