0

please help with the following issue. I have deleted some records in a table in SQL, without realizing that once I delete them, then the new records are not auto-incremented. For example, I deleted records from 5 to 10, and the new record gets number 11, while I want 6.

How can this be fixed? And what is the method to delete only the data, so that auto-increment would still work?

Veronique
  • 23
  • 7
  • Does this answer your question? [Auto Increment after delete in MySQL](https://stackoverflow.com/questions/2214141/auto-increment-after-delete-in-mysql) TL;DR don't do this unless you _really_ need to, in which case you should remove the AUTO INCREMENT and handle your IDs manually in code. – WOUNDEDStevenJones Mar 23 '21 at 19:21
  • Which dbms are you using? Most products have their own versions. – jarlh Mar 23 '21 at 19:30
  • Also, re-using 6 is bad idea. Keep generating new numbers. – jarlh Mar 23 '21 at 19:31
  • Why do you want to put some intelligence in autoincremented key? It is not a good idea, no matter what the identifier will be. Also please tag your dbms since the solution may be different – astentx Mar 23 '21 at 19:31
  • I wanted to re-use 6 more for neat appearance. The other post (Auto Increment after delete in MySQL) actually answers my question more than enough. Thanks! – Veronique Mar 23 '21 at 19:42
  • It's not the job of a database to look neat. Neatness is the role of the presentation layer - your application. The primary task of the database is to maintain accurate data. Fiddling with DDL commands as part of everyday business operations risks that. – Tangentially Perpendicular Mar 23 '21 at 21:23

0 Answers0