DB
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit
Action
After a data migration – from an old table to a new table – we created a new sequence and executed this command to sync it's next value to be equal to table maximum id.
SQL
-- SYNC SEQUENCE WITH TABLE
SELECT level, {SEQUENCE_NAME}.NEXTVAL
FROM dual
CONNECT BY level <= (
SELECT MAX(ID)
FROM {TABLE}
);
Question
- Is there any side effect on calling this SQL – since the keyword
CONNECT
is used to make connections to DB ? - Is there a more efficient way to do such task?
Best Answer
CONNECT
in this context has nothing to do with database connections.hierarchical_query_clause ::=
You can change the increment of a sequence to set it to a required value. Example:
You can also use the undocumented
RESTART
clause, but that does not work in 11.2: