Monday, March 1, 2010

bumping one particular sequence

----------------checking the nextval in seq---------
conn platform/platform
select SCDB_SUBSCRIPTIONS_ID_SEQ.nextval from dual;

NEXTVAL
----------
140
----------------checking max id in table which is using seq----------

conn scdb_user/scdb_user

select max(id) from SCDB_SUBSCRIPTIONS;

MAX(ID)
----------
50236


note: here table id is more than sequence.
________________________________________________-


so difference b/w table id and seqnnextval should be incremented

50236
- 140
________
50096

SQL> alter sequence platform.SCDB_SUBSCRIPTIONS_ID_SEQ increment by 50096;

Sequence altered.

SQL> select SCDB_SUBSCRIPTIONS_ID_SEQ.nextval from dual;

NEXTVAL
----------
50237


SQL> conn scdb_user/scdb_user

SQL> select max(id) from SCDB_SUBSCRIPTIONS;

MAX(ID)
----------
100333

note: here scdb_user is accessing the sequence of platform user to insert a row in SCDB_SUBSCRIPTIONS table
_____________________________________________________________________________________________________________-