0

I have a database created with its id on autoincrement. However after deleting records and adding a new record, the id of the new record started from the id of the last deleted record instead of the id of the last available record

My data table:

id name surname
1 Alice Smith
2 Jordan Reins
3 Echo Raymond
with sqlite3.connect("names.db") as connection:
    cursor = connection.cursor()
    cursor.execute("DELETE FROM names WHERE id > 1;")

Then later:

with sqlite3.connect("names.db") as connection:
    cursor = connection.cursor()
    cursor.execute("INSERT INTO names (name, surname) VALUES(?, ?);", ("Bob", "Marley"))

I was hoping that to see:

id name surname
1 Alice Smith
2 Bob Marley

However I got:

id name surname
1 Alice Smith
4 Bob Marley
Rafalon
  • 4,450
  • 2
  • 16
  • 30
Echo
  • 1
  • 1

0 Answers0