[mysql + php] Auto Increment Resetten

Pagina: 1
Acties:
  • 42 views sinds 30-01-2008

  • IJnte
  • Registratie: Juni 2003
  • Laatst online: 19-05 12:01
Ik ben al ver gevorderd met mijn uren registratie programmatje, maar ik loop weer eens tegen een probleem aan.
Ik wil aan de hand van een id een rij uit de mysql kunnen verwijderen. Ik heb in mysql een kolom Id. Dit is de primairy key, en is auto increment.

Ik weet hoe ik het verwijderen moet doen. Als ik nu een rij verwijder, hou ik een gat over in mijn ID's. Het gaan dan b.v. van 1,2,4,5,6 enz.
Wat ik graag zou willen is dat de auto_increment gereset wordt nadat er een ID is verwijdert. Als het goed is moeten dan de ID's weer goed gerankschikt worden.

Ik had gevonden dat dit als volgt moet:
code:
1
alter table id auto_increment = 1;

Bron

Hoe moet ik dit in een PHP script zetten? Ik ben er al een poosje mee bezig geweest maar ik krijg het niet voor elkaar.

Exploring the world by bicycle! cyclingsilk.wordpress.com


  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Waarom zou je je ID willen resetten :? Het is toch alleen bedoeld als identificatie?

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


  • daaan
  • Registratie: Maart 2000
  • Laatst online: 03-12-2025

daaan

Brandweer Zoutkamp

Van mysql.org:

For those that are looking to "reset" the auto_increment, say on a list that has had a few deletions and you want to renumber everything, you can do the following.

DROP the field you are auto_incrementing.
ALTER the table to ADD the field again with the same attributes.

You will notice that all existing rows are renumbered and the next auto_increment number will be equal to the row count plus 1.

(Keep in mind that DROPping that column will remove all existing data, so if you have exterior resources that rely on that data, or the numbers that are already there, you may break the link. Also, as with any major structure change, it's a good idea to backup your table BEFORE you make the change.)

One's never alone with a rubber duck.


  • gorgi_19
  • Registratie: Mei 2002
  • Laatst online: 20:27

gorgi_19

Kruimeltjes zijn weer op :9

Zie onder andere [rml][ MySql] Records opnieuw nummeren.[/rml]

Dit onderwerp is afgelopen maand geregeld langs gekomen. :) Zie ook de search meer meer topics over dit onderwerp.

[ Voor 5% gewijzigd door gorgi_19 op 28-06-2004 16:37 ]

Digitaal onderwijsmateriaal, leermateriaal voor hbo


Dit topic is gesloten.