July 05, 2015

How to reset sequence

Hello folks, long time no see.. :)

simple thing but very important, how to reset sequence

testcase is to reset to 1

1. Check current sequnce detail
select SEQUENCE_NAME, MIN_VALUE, MAX_VALUE, INCREMENT_BY, LAST_NUMBER, CYCLE_FLAG from user_sequences  where SEQUENCE_NAME='SEQ_NAME';

SEQUENCE_NAME   MIN_VALUE  MAX_VALUE INCREMENT_BY LAST_NUMBER 
-------------- ---------- ---------- ------------ ----------- 
SEQ_NAME           1       999999999       1      330120        


2. Alter sequence increment by doing some minus here
33012-1= 330119
alter sequence SEQ_NAME increment by -330119 ;

3. Select next value from sequence
select SEQ_NAME.nextval next from dual;

4. Alter sequence increment to 1 again
alter sequence SEQ_NAME increment by 1;

5. let's verify
select SEQUENCE_NAME, MIN_VALUE, MAX_VALUE, INCREMENT_BY, LAST_NUMBER, CYCLE_FLAG from user_sequences  where SEQUENCE_NAME='SEQ_NAME';
SEQUENCE_NAME   MIN_VALUE  MAX_VALUE INCREMENT_BY LAST_NUMBER
-------------- ---------- ---------- ------------ -----------
SEQ_NAME           1       999999999       1      1


Olrait !! done




No comments:

Post a Comment