I have to modify an existing table in a Oracle 10g DB with a few thousand records to add a surrogate autonumber key. One way that comes to my mind is to
Is there an easier or more efficient way of doing this (or is there some reason why this wouldn't work)?
I'd do it the following way:
Create the id
column, allowing null values
Issue this query:
UPDATE mytable
SET id = rownum
Alter table to add NOT NULL
and PRIMARY KEY
for the new id column
Create the sequence, seeding it to MAX(id) + 1
and use it for the further inserts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With