Oracle 9 - Resetting Sequence to match the state of the table

Viewed 30425

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?

7 Answers
  • select max value from table & set sequence value to it.

SELECT setval( 'table_id_seq_name', (SELECT MAX(id) FROM table_name ) );

Related