0

I have a table with existing data that has a unique and auto increment key column named "_id" and several other columns and because this was a test database, I deleted some random rows and would like to reset my _id column to 1 and auto fill the existing _id rows automatically by adding +1 (same as auto increment). It will be easier if I explain using images, please see below:

enter image description here

Next inserted row will auto increment _id to "6".

Community
  • 1
  • 1
user3560827
  • 632
  • 1
  • 5
  • 22

1 Answers1

0

please try following sql: ALTER TABLE "tablename" AUTO_INCREMENT = 1

  • Even if you set `AUTO_INCREMENT=1`, it will automatically increase to the `MAX(_id)+1` anyway. Auto-increment will never generate a new value less than the greatest existing value. So it won't fill in the gaps. – Bill Karwin Feb 20 '19 at 20:24