How to reset a sequence
                                                 Last update (2011-05-15 00:29:46)
                                                                                                                   Date added (2008-02-22 11:52:58)

Summary
Lets say that you have a sequence called "TEST" which increments by 1 and now has a value of 8 and you want to reset it back to 0!

Tip: The Solution is not to drop the sequence and recreate it with the new attributes because dropping it will make invalid all the depended objects. The workaround follows:

Create the sequence
CREATE SEQUENCE TEST
START WITH 0
INCREMENT BY 1
MINVALUE 0
NOCACHE 
NOCYCLE 
NOORDER;
Query the sequence to see where is the next value right now
SELECT TEST.NEXTVAL S FROM DUAL;
Lets say that the result from the previous query is 8.
Alter the sequence
ALTER SEQUENCE TEST INCREMENT BY -8 MINVALUE 0;
Query the sequence next value
SELECT TEST.NEXTVAL S FROM DUAL;
Alter the sequence to the initial creation phase
ALTER SEQUENCE TEST INCREMENT BY 1 MINVALUE 0;
NOW YOU ARE AT 0 next value Check it out.
SELECT TEST.NEXTVAL S FROM DUAL;
Reviews
Categories
Oracle DBA-> (147)
  Alertlog (3)
  Archivelog (5)
  Auditing (1)
  Backup - Recovery (19)
  Database files (6)
  Database options (2)
  DB links (2)
  Dependencies (1)
  Dictionary (2)
  Exp-Imp Datapump (6)
  Jobs (2)
  Mview (2)
  Networking (3)
  Objects (7)
  Parameters (2)
  Redologs (6)
  Roles - Grants (2)
  Rollback - Undo (8)
  Segments (3)
  Sequences (2)
  Sessions (14)
  SGA (14)
  Tables (10)
  Tablespaces (10)
  Temp (4)
  Toad (5)
  Transactions (1)
  Upgrade (2)
  Users (3)
Oracle APPS DBA-> (66)
Exadata (1)
Performance Tuning-> (59)
Oracle Real Cases (24)
Oracle Errors (23)
Oracle SQL tricks (32)
Oracle RAC (3)
Oracle Security (8)
Filters
Search