I am using IDENTITY
feature of oracle 12 c to increment record id of a table.
As part of initial setup we have to migrate some records from another system to this table. these records are non sequential records(Partial records are deleted).
How to make identity to always create highest value + 1
based on the table records.
After googling for different options found keyword of RESTART WITH
value option. For this we need to create a new store procedure and alter all the tables with highest possible values to restart with.
Is there any direct keyword which can be used along with IDENTITY
which can force it to always regenerate higher values. ?
This has become super easy in 12c
alter table your_table modify (id generated by default on null as identity
start with limit value);
Then the next insert will safely insert using a sequence that has been automatically reset to what is essentially max(id)+1 https://docs.oracle.com/database/121/SQLRF/statements_3001.htm#SQLRF01001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With