+6  A: 

I'd do it the following way:

  1. Create the id column, allowing null values

  2. Issue this query:

    UPDATE  mytable
    SET     id = rownum
    
  3. Alter table to add NOT NULL and PRIMARY KEY for the new id column

  4. Create the sequence, seeding it to MAX(id) + 1 and use it for the further inserts.

Quassnoi
Hi, why do you use max(id)+1 when you can use a sequence ?update mytableset id=sequence.nextval
Rene
@Rene: whenever a sequence runs out of the cached values, it is updated which generates a redo log entry. Using `rownum` is much faster.
Quassnoi
Quassnoi, I agree with your approach if we're dealing with megarows and I've given it a vote. But it seems like overkill for "a few thousand rows" as stated by the initial question. Both ways will work.
Jim Hudson
@Jim: sure they will, though I hardly see an overkill here :)
Quassnoi