Understanding sqlite android auto grow field

I have a table in my sqlite database for Android. There is an id field that is an automatic increment of the primary key. My application service inserts a row every minute in a table. At some point, I delete the record older than 5 days. So the general record is limited. But the identifier is increasing. So I got confused about the id value as it increases with each new record. What will be the condition when the "id" field exceeds the maximum value ?. What is the maximum value of this field? How to work with it in the given circumstances? Can I really work with the auto-increment field here?

Table creation statement:

create table datausage (id integer primary key autoincrement," + "date date not null,time text not null,level integer) 
+6
source share
3 answers

See this for white papers. The biggest possible ROWID is 9223372036854775807, which, if you write 1000 entries, will last more than 10675199116 days: I donโ€™t think it will be difficult for you.

When this is achieved, the database will begin to collect unused identifiers, so you will be fine too.

Use AUTO INCREMENT: this is the best option for you.

EDIT: also, this is called AUTO INCREMENT for some reason. It should automatically increase.

+20
source

The primary key with auto-increments will continue to increase forever (in our conditions) and will not replace deleted records. Even if you delete old entries, the id field will increase continuously.

As stated in other answers, there is also enough space for the field.

+4
source

You do not need to use auto-increment, if you want to put your own values โ€‹โ€‹according to your logic, it will increment the value each time you insert a row. Instead, you can drop the table and recreate the table if you want to use auto-increment.

0
source

Source: https://habr.com/ru/post/892639/


All Articles