开发者

Understanding android sqlite auto increment field

开发者 https://www.devze.com 2023-03-20 02:35 出处:网络
I have a table in my android sqlite database.There is a field \'id\' which is auto increment primary key.My application service inserting a row in every minutes in the table.At some point in time i am

I have a table in my android sqlite database.There is a field 'id' which is auto increment primary key.My application service inserting a row in every minutes in the table.At some point in time i am deleting the entry older than 5 days.So total entry is limited.But id is increasing.So i am confuse about the value of the id as it is increasing with each new entry.What will be the condition when 'id' field exceed maximum value?. what is the maximum value of this field?How to work with this under the circumstances?Can i really work with auto increment field here?

The table Creation statement:

create table datausag开发者_运维知识库e (id integer primary key autoincrement,"
            + "date date not null,time text not null,level integer)


See this for the official docs. The largest possible ROWID is 9223372036854775807, which if you are writing 1000 entries a second will last more than 10675199116 days: I don't think you'll have difficulty with that.

When that is reached the database will start picking unused IDs, so you'll also be fine.

Use AUTO INCREMENT: it is the best option available to you.

EDIT: also, it is called AUTO INCREMENT for a reason. It is supposed to automatically increase.


An auto-incrementing primary key will continue to increment forever (in our terms) and will not replace deleted records. Even if you delete old records the id field will increment continuously.

As has been stated in other answers there is more than enough space for the field as well.


You need not use autoincrement if you want put your own values as per your logic,it will increment the value every time you insert a row.Instead you can drop table and recreate table if you want use autoincrement.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号