SQLite空表和自动增量字段 [英] SQLite empty tables and autoincrement field

查看:117
本文介绍了SQLite空表和自动增量字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一个带主键,自动递增ID字段的sqlite表.
一旦我使用delete命令删除了所有行,并且在此之后尝试插入Id字段时,它不是从0开始,而是从以前的max + 1值开始.
在mysql中,如果我们使用空表命令并再次插入,那么我们将从1开始再次获得ID.
如何在sqllite中实现相同的目标.
我的真正目的是一旦表包含1000条记录,我想删除所有记录并再次从id = 1开始

Hello,
i have an sqlite table with primarykey,autoincrement Id field.
Once i use the delete command to remove all rows and after this when i try to insert the Id field is not starting from 0, instead its starting from previous max+1 value.
In mysql if we use empty table command and insert again , then we get the Id starting from 1 again.
How can i achieve the same in sqllite.
My real aim is once the table contains 1000 records i want to remove all records and start from id=1 again

推荐答案

您可以删除并重新创建表,或者
You can drop and recreate the table, or
delete from sqlite_sequence where name=''%TABLE NAME%''; 


更多信息:
http://sqlite.org/autoinc.html [


More info:
http://sqlite.org/autoinc.html[^]

Good luck!


使用此功能(其中tablename是您的表):

Use this (where tablename is your table):

DELETE FROM tablename;    
DELETE FROM sqlite_sequence WHERE name = 'tablename';


这篇关于SQLite空表和自动增量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆