我有一些表在sqlite和我试图找出如何重置自动增量数据库字段。
我读到DELETE FROM tablename应该删除一切,并将自动递增字段重置为0,但是当我这样做它只是删除数据。当插入新记录时,autoincrement将在删除之前从中断处继续。
我的ident字段属性如下:
>字段类型:整数
>字段标志:PRIMARY KEY,AUTOINCREMENT,UNIQUE
是不是我在sqlite Maestro构建表,我在sqlite Maestro中执行DELETE语句?
任何帮助将是伟大的。
尝试这个:
delete from your_table; delete from sqlite_sequence where name='your_table';
sqlite keeps track of the largest
ROWID that a table has ever held using
the specialsqlITE_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.