Update serial ID when a table is NULL

-1

I'm doing a desktop program in java, with the ID of a product being incremented automatically by SERIAL.

However, when I delete some element or all, the value of the sequence remains the last one that was added on, and I have to go there in the bank and change that value by hand.

Does anyone have an idea of a trigger or can I change this in the same sequence's own settings?

    
asked by anonymous 25.01.2016 / 13:43

2 answers

3

This is the expected behavior of an autoincrement field of a DB, it does not make much sense for you to search for a deleted ID and force the DB to add this ID to the new one, you will lose a lot of performance, so imagine your table with 2000 items or but this is not good practice.

    
25.01.2016 / 18:21
0

You can reset the value of a serial field, with

ALTER SEQUENCE nome_da_sequence RESTART WITH 1

Based on: link

    
25.01.2016 / 13:51