Sequencereset

301 views

Published on

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
301
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sequencereset

  1. 1. Resetting a Sequence Administration TipsResetting Sequence NumbersThe standard advice is that the only way to re-set a sequence number back to its startingvalue is to drop it and re-create it. This, of course, complete hog-wash (besides which,droping a sequence invalidates all triggers, procedures and packages which reference it).Consider this sequence:SQL> SELECT * FROM DBA_SEQUENCES WHERE SEQUENCE_OWNER=SCOTT;SEQUENCE_NAME MIN_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER------------------ ---------- ------------ - - ---------- -----------SEQ_BLAH 1 1 N N 20 21Youll note that this sequence is cache-able, which means we cant rely on thatLAST_NUMBER column to tell us where the sequence is really up to. The only reliable wayto do that is to select the next sequence number directly:SQL> SELECT SEQ_BLAH.NEXTVAL FROM DUAL; NEXTVAL---------- 22This gives us the crucial piece of information we need -the true last number issued. If younow issue this command:SQL> ALTER SEQUENCE SEQ_BLAH INCREMENT BY -22 MINVALUE 0;...then the sequence would be effectively set to 0 if we were to select the next value fromit just one more time (note the "minvalue" has to be adjusted to allow this zero number).Selecting the nextval one more time therefore yields:SQL> SELECT SEQ_BLAH.NEXTVAL FROM DUAL; NEXTVAL---------- 0Now, one final bit of tidying up needs to be performed: the sequence needs its normalincrement by to be re-instated:SQL> ALTER SEQUENCE SEQ_BLAH INCREMENT BY 1;Copyright © Howard Rogers 2001 10/18/2001 Page 1 of 2
  2. 2. Resetting a Sequence Administration TipsThe next person to select from the sequence will now be assigned sequence 1 -which iswhat you wanted all along.Clearly, if people are continuing to select from this sequence as you are trying to reset it,you can expect all sorts of weird results. This task is best done in, for example,RESTRICTED SESSION, so that only you are working on it at the time it is reset.Copyright © Howard Rogers 2001 10/18/2001 Page 2 of 2

×