-1
I’m making a java desktop program, with a product ID automatically incremented by SERIAL.
However, when I delete some element or all, the value of the sequence stays on the last one that was added on, and I have to go to the bank and change that value by hand.
Does anyone have an idea of a Rigger or if I can change this in the settings of the sequence itself?
Because you need to reset the serial?
– rray
Because when I delete something from the table it doesn’t update the id.
– Joana
Doesn’t update the id, would that be what exactly? what would you expect?
– rray
I delete a product with id 1, the next product I register in the system gets id 2. The same thing if I delete a table with 600 products, if I register a new product it starts with 601.
– Joana
This is the expected behavior, you do not 'reuse' ids, either because there are related records in other tables and mainly the effort to reorder all records.
– rray
Related: http://answall.com/q/78544/3084
– cantoni
I share what @rray said and reinforce that trying to repurpose Ids is something that requires a completely unnecessary effort.
– cantoni
What is expected behavior if you have ids, 1 to 10 and you delete 7? register the new as 7, or readjust all of the following for the next one to be 10?
– Guilherme Lautert
This is a situation that almost every database beginner goes through, thinking that they’re missing something by "wasting" serial/autoincrement Ids and that repurposing it will bring some benefit. @Joana unless you have a problem really Specifically this repurposing is a bad idea, if you have please add on the question because I have honestly never seen one and am curious ;p
– BrunoRB