Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding android sqlite auto increment field

Tags:

android

sqlite

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 datausage (id integer primary key autoincrement,"
            + "date date not null,time text not null,level integer)
like image 398
Rasel Avatar asked Jul 13 '11 04:07

Rasel


2 Answers

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.

like image 84
Femi Avatar answered Oct 12 '22 01:10

Femi


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.

like image 31
Fergus Barker Avatar answered Oct 12 '22 00:10

Fergus Barker