Link to home
Start Free TrialLog in
Avatar of manoj_cts
manoj_cts

asked on

Oracle Sequence - Last value need to be Max of primary key column +1

How to alter my sequence so that last value of sequence should be one more than the max value value of primary key cloumn of the table.
It seems i need to have a procedure which will alter all the sequences at one shot.
Could any one suggest me on this..



Avatar of markag
markag

You cannot alter the Start with of a sequence. You must drop it and recreate it.

-- Get max value of current pk
Select MAX(MY_PK) + 1 FROM MY_TABLE;

-- returns...
12345

-- drop and recreate sequence
DROP SEQUENCE MY_SEQUENCE;

CREATE SEQUENCE MY_SEQUENCE START WITH 12345 increment by 1 ...yadda yadda yadda

HTH,
Mark
Avatar of manoj_cts

ASKER

This is fine but it will can be done every time.I want to have a procedure which will do it for all the sequences.
ASKER CERTIFIED SOLUTION
Avatar of markag
markag

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial