Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: primary and foreign keys
Ronnie,
How about using a sequence. insert into the table with sequence_name.nextval
A PL/SQL script in a procedure or a trigger would work nicely to populate
the unique key field
by selecting the nextval off the sequence everytime an insert is done on the
table.
Nevin Hahn
ICG Communications
Ronnie Braverman wrote in message <35BFD48E.10B1D83D_at_dsto.defence.gov.au>...
>Hi there.
>I have table X with the primary key PK_X consisting of five
>columns.
>I have table Y with a foreign key FK_Y the same columns as
>those in PK_X.
>Since the number of rows in Y is going to be huge, I'd like
>to avoid duplicating the key columns in both tables X and Y.
>What I would like to have is some unique id (eg a unique
>number) being generated for every row in table X which I could
>then use as the primary key for X and the foreign key for Y.
>The problem is that I do not know how to generate a unique
>id (other than the [maximum of the column] + 1, but since the
>number of rows are going to be huge and rows will be added and
>deleted continuously, this is not a good long term solution).
>Any ideas?
>Thanks,
>ronnie Braverman
Received on Thu Jul 30 1998 - 01:50:29 CDT
![]() |
![]() |