Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Referencing an Oracle Sequence
If I have an Oracle sequence identified as a primary key in one table
how do I reference that sequence in another table. For example I have
customer_id as a sequence and primary key in the customer table. Then
I want to reference customer_id in the orders table by making
customer_id a column in the orders table and a FK reference the PK the
in customer table. What I really want to know is when I use insert
statements to enter the information for the orders table what do I put
in for customer_id?
create table CUSTOMER (
customer_id VARCHASR(10),
constraint CUSTOMER_ID_PK PRIMARY KEY (customer_id))
CREATE sequence customer_id
increment by 1
start with 10000
NOCACHE
ORDER;
insert into orders values (customer_id.NextVal);
Thanks.
create table ORDERS (
orders_id VARCHAR2(10),
customer_id VARCHASR(10),
constraint ORDERS_ID_PK PRIMARY KEY (orders_id),
constraint ORDERS_FK
FOREIGN KEY(customer_id) REFERENCES customer (customer_id));
insert into orders values ('0000000001','<??WHAT GOES HERE??>'); Received on Sat Apr 13 2002 - 16:25:19 CDT