Jack
Jack

Reputation: 815

Oracle Sequence start with doubt

I am trying to autonumber Id field in one of my table. Table already has 40 rows of data but now if i autonumber the id field do i have to specify start with as 41 or not? Thank you

Do i have to do this

create sequence EMP.SEQ_ID
minvalue 1
maxvalue 99999999999999999
start with 41
increment by 1
cache 50
order;

or only this will work

create sequence EMP.SEQ_ID
minvalue 1
maxvalue 99999999999999999
increment by 1
cache 50
order;

Upvotes: 1

Views: 178

Answers (1)

NullUserException
NullUserException

Reputation: 85478

If you don't specify START WITH, it starts at 1.

So if you are using this for a primary key and there are already rows with IDs from 1 to 40, it will fail.

PS: You can use this:

CREATE SEQUENCE EMP.SEQ_ID
START WITH 41
NOMAXVALUE
CACHE 50;

(it increments by 1 by default).

Upvotes: 5

Related Questions