Search code examples
androidsqliteauto-increment

sqlite autoincrement function


I am writing an app that controls many tables in a database. I am using the AUTOINCREMENT method of sqlite. The items corresponding to the AUTOINCREMENT '_id' collumn will be having their unique ids as the values in the '_id column'

Is it advisable to use this method to assign unique ids to every item. Because i donot know what will happen to the numbering system if I write a method to remove certain rows from the table.

I mean that if once the table is created with certain entries and then the user decides to remove certain rows, will the autoincrement column re-number itself (which will lead to wrong ids being assigned to the corresponding items) or not.


Solution

  • Deleting rows from a table will not reset the auto increment ID. That is, suppose you have created rows 1, 2 and 3. If you delete 2, the next row you insert will still have an ID of 4, i.e, you would now have rows 1, 3, 4 in the database.