1

I have a method like this:

private void insertData() {

    ContentValues cv = new ContentValues();
    cv.put(name, "aName");
    cv.put(lastName , "aLastName");

    Uri returnedUri = getContentResolver().insert(CONTENT_URI, cv);
    Log.e("number of row : " , returnedUri.toString());

}

I have 4 rows in my database and in the log message it will return .../persons/31 or a greater number each time. I expect that new inserted person should have id 5. I think every time I add a new person id increase by one but after deleting a person id won't automatically decrease by one.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
amir_70
  • 737
  • 1
  • 10
  • 27

2 Answers2

1

The id will never decrease after delete the person because id is the unique key for every person it means if you delete one person it can not give that person identity which is id in this case to another person.Got it?

Deepak Rana
  • 539
  • 4
  • 18
  • thanks for your answer . yes i got it . but what should i do now ? i want the returned id be 5 not 31 or some bigger number . what can i do for it ? – amir_70 Aug 04 '17 at 15:50
  • can i know your the requirement for which purpose you want this...if you know your answer than please tick my answer and upvote my answer – Deepak Rana Aug 04 '17 at 15:54
1

This is pretty typical of SQL databases, while I don't know exactly why, or how, but they have an incremental on add counter, which means every new insertion will be +1 whatever the last value of the counter is. As best i know there's no way around this short of resetting the database

TheCog19
  • 1,129
  • 12
  • 26