user1066183
user1066183

Reputation: 2584

Oracle update table adding ID column

In Oracle 11 I have a table without an ID column. I have create it:

CREATE SEQUENCE myDb.mySeq
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  INCREMENT BY 1
  NOORDER;

alter table MyTable add(ID NUMBER NOT NULL);

But now i must update all existing record with the new ID column. How I can do it?

Upvotes: 0

Views: 128

Answers (1)

Erich Kitzmueller
Erich Kitzmueller

Reputation: 36987

All you need is

update mytable set id=mySeq.nextval;

Upvotes: 3

Related Questions