I have a sequence used to seed my (Integer based) primary keys in an oracle table.
It appears this sequence has not always been used to insert new values into the table. How do I get the sequence back in step with the actual values in the table?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If ID is the name of your PK column and PK_SEQ is the name of your sequence:
Find the value of the highest PK by
SELECT MAX(ID) FROM tableName
Find the value of the next PK_SEQ by
SELECT PK_SEQ.NEXTVAL FROM DUAL
done, assuming you treat these
values as true surrogate keys
jump to the max ID by ALTER SEQUENCE
PK_SEQ INCREMENT BY [#1 value – #2
value]
Bump the sequence by SELECT
PK_SEQ.NEXTVAL FROM DUAL
Reset the sequence increment value
to 1 by ALTER SEQUENCE PK_SEQ
INCREMENT BY 1
This all assumes that you don’t have new inserts into the table while you’re doing this…