SQLite Reset Primary Key Field

Posted Chuck Lu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLite Reset Primary Key Field相关的知识,希望对你有一定的参考价值。

SQLite Reset Primary Key Field

回答1

Try this:

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.

 

回答2

You can reset by update sequence after deleted rows in your-table


UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME=\'table_name\';

 

 

delete from goods_goodscategory

where id>6




select * from sqlite_sequence

update sqlite_sequence

set seq=6

where name=\'goods_goodscategory\'

 

MYSQL 的 primary key 和unique key 的区别

参考技术A   嘿嘿
用一句顺口的话来说
  区别就是一个表只能定义一个primary
key,但可以定义多个unique
key,primary
key
必须不空不重(chong),unique
key
不空,但可以允许有一个空值。

以上是关于SQLite Reset Primary Key Field的主要内容,如果未能解决你的问题,请参考以下文章

SQLite:*防止* PRIMARY KEY 值在删除所有行后重置 [重复]

sqlite中的自增主键

$ bundle exec rake db:reset 命令提升无法删除 db/development.sqlite3

CentOS 6 - YUM 不起作用 - primary.sqlite.bz2 [错误 -1] 元数据文件与校验和不匹配

SQLite PRIMARY 键自动增量不起作用

text 找不到ID为primary的连接池。带有rails 5的sqlite3错误