Auto update of MySql row numbering -


i have made table in mysql column "id" auto_increment , primary_key. made 3 rows, namely 1,2,3. deleted no. 2 row numbering remains 1, 3. how change 1,2.
mysql table

the short answer is: you don't. changing multi step problem can error prone if don't right. frankly, (if ever) makes sense so.

things involved in such task:

  1. delete row don't want (you've done that)

  2. subtract 1 id of every id that's >= row deleted.

  3. update auto increment counter @ 1 less current.

  4. do same thing tables in foreign key.

if want delete multiple rows, logic gets more complicated quickly. either way, take considerable resources , wreak havoc foreign keys.

such action goes against principles of how 1 use database. rdms not flat file excel spreadsheet. delete rows , let there gap in auto incremented id, doesn't make difference whatsoever application.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -