How to reset the IDENTITY column in oracle to a new value

I am using the oracle 12 c IDENTITY function to increment the table record id.
As part of the initial setup, we need to transfer some records from another system to this table. these records are not consecutive records (Partial records are deleted).

How to make an identifier, always creating a maximum value + 1 based on table entries.

After searching for keywords for the keyword RESTART WITH . To do this, we need to create a new storage procedure and change all the tables with the highest possible values ​​for restarting.

Is there any direct keyword that can be used with IDENTITY that can cause it to always return to higher values.

+5
source share
2 answers

It became very 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 be safely pasted using a sequence that was automatically reset to what is essentially max (id) +1 https://docs.oracle.com/database/121/SQLRF/statements_3001.htm#SQLRF01001

+3
source

There is no direct keyword, and you need to modify the table (the correct words START WITH).
There is another way to change the highwatermark for the identity column. As for common sequences (by the way, identity is built on a system sequence), use the old INCREMENT BY trick to move the label in any direction.

 ALTER TABLE T MODIFY (ID NUMBER GENERATED ALWAYS AS IDENTITY INCREMENT BY 50 NOCACHE); 

That is, if at present the next value is 100, and you need to make it 1000, you do this trick two times: "increase by 900", add a record and backward "increment by 1" (if the identity is in step 1).

+1
source

All Articles