UID generation in oracle - how?
Date: 1999/03/08
Message-ID: <36E34DFA.C5199332_at_exmachina.net>#1/1
I've 77.4MB of PDF's to search through for this -
surely it's been done before!
How does one normally generate a unique ID?
Is there a datatype that autoincrements itself?
I thought about using the builtin ROWID, but they're not portable across database installations (eg If I refer to a rowid via a foreign key, and then unload the data, the constraints would be broken when loading the data into a seperate installation, because the rowid's depend on blocksize & offsets etc)
Or maybe the thing to do is to use triggers?
what's the SOP in oracle?
I'm going to go with the following in the meantime:
create table pk_values
(
TABLE_ID number(9) not null primary key,
TABLE_NAME varchar2(32) not null,
NEXT_UID number(9) not null
);
insert into pk_values(TABLE_ID,TABLE_NAME,NEXT_UID)
select t.table_name, o.object_id, t.num_rows
from all_objects o, all_tables t
where o.object_type = 'TABLE'
and o.object_name = t.table_name;
and then
set transaction read write read committed; select next_uid from pk_values where table_id=:whatever for update; update pk_values set next_uid=next_uid+1 where table_id=:whatever; commit;
comments? suggestions?
john
Received on Mon Mar 08 1999 - 00:00:00 CET