Deleting hole row.....

Deleting hole row.....

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

when i delete a row i want to decrement the ID field.
example
let's say i have a table with those values
ID | name |
1 | Ivan |
2 | bojan |
3 | ranko |

and when i want to delete the second row, the third row to be decremented like this
ID | name |
1 | Ivan |
2 | ranko |

anyone know the command?



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • Pridružio: 19 Jun 2007
  • Poruke: 33
  • Gde živiš: Grad Beograd

Well, It is not good solution to change ID. But if You have to do it, I will suggest You to make cascade trigger which will go through all tables where this key is used, and change id. It is very bad solution, but You asked for it.

And, here is pseudo code for changing ID.

FOR n := DeletedID+1 to RowCount
Id := Id - 1
ENDFOR



offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

hmmmm that is for mysql?

I readed somewhere that i can use "pack" at the end of the statemant, but it's not working or i m not using in the right way.

Ko je trenutno na forumu
 

Ukupno su 1074 korisnika na forumu :: 50 registrovanih, 10 sakrivenih i 1014 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., Atomski čoban, babaroga, BlekMen, Bobrock1, bojank, BraneS, cavatina, Denaya, Dimitrije Paunovic, Dimitrise93, DonRumataEstorski, Dorcolac, dragoljub11987, FOX, Frunze, Gargantua, goxin, Grah0, ivica976, kunktator, Leonov, MaksicZoran, milenko crazy north, mkukoleca, MrNo, naki011, Nemanja.M, nuke92, operniki, ozzy, panzerwaffe, Parker, pein, procesor, raptorsi, RJ, sasa76, slonic_tonic, Smiljke, solic, Srle993, stegonosa, Sumadija34, torivoje, Tvrtko I, VP6919, YugoSlav, zodiac94, 125