gpt4 book ai didi

SQLite 重置主键字段

转载 作者:IT王子 更新时间:2023-10-29 06:16:47 25 4
gpt4 key购买 nike

我在 SQLite 中有几个表,我正在尝试弄清楚如何重置自动递增的数据库字段。

我读到 DELETE FROM tablename 应该删除所有内容并将自动增量字段重置回 0,但是当我这样做时它只会删除数据。插入新记录时,自动增量将从删除前停止的地方开始。

我的ident字段属性如下:

  • 字段类型:整数
  • 字段标志:PRIMARY KEYAUTOINCREMENTUNIQUE

我在 SQLite Maestro 中构建表并且也在 SQLite Maestro 中执行 DELETE 语句是否重要?

任何帮助都会很棒。

最佳答案

试试这个:

delete from your_table;    
delete from sqlite_sequence where name='your_table';

SQLite Autoincrement

SQLite keeps track of the largest ROWID that a table has ever held using the special SQLITE_SEQUENCE table. The SQLITE_SEQUENCE table is created and initialized automatically whenever a normal table that contains an AUTOINCREMENT column is created. The content of the SQLITE_SEQUENCE table can be modified using ordinary UPDATE, INSERT, and DELETE statements. But making modifications to this table will likely perturb the AUTOINCREMENT key generation algorithm. Make sure you know what you are doing before you undertake such changes.

关于SQLite 重置主键字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1601697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com