Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> foreign Key creation SQL help needed!
This is for an SQL class homework assignment.
..Now that that's out of the way :)
problem 1 was
to create a table with a
colA of type Number
and
colB which was varchar2(20)
problem2 was -
To make colA and colB a composite primary key
Now I have to (problem3)...
--Change the homework table so that colB can only contain values that
--are stored in the order# column of the orders table. Make certain
--that after the change, colB is still part of the composite key
--primary key created in step two.
I did the first two problems, but when I try to create the foreign key (which I believe is what I need to do to acheive the above) I got an error that the column type is incompatable with the referenced column type. ((The order# column in orders is Number))
I ended up doing...
ALTER TABLE SCOTT.HOMEWORK
MODIFY COLB NUMBER;
ALTER TABLE SCOTT.HOMEWORK
ADD CONSTRAINT COLB_ORDERS_ORDER#_FK
FOREIGN KEY (COLB)
REFERENCES SCOTT.ORDERS (ORDER#)
ON DELETE CASCADE;
But I wonder if I was somehow supposed to make it work with the colB still being varchar2 type..
Anyone have any thoughts on that? or advice?
Thanks afforhand :)
Tony! Received on Thu Oct 23 2003 - 22:39:45 CDT
![]() |
![]() |