Home » SQL & PL/SQL » SQL & PL/SQL » referencing a composite primary key as foreign key (oracle, ??, linux)
referencing a composite primary key as foreign key [message #340363] Tue, 12 August 2008 08:29 Go to next message
miek
Messages: 1
Registered: August 2008
Junior Member
I have a table 'FinishedTrack' whose primary key is composite, (it consists of the attributes 'originates_from' and 'version'), I want to create another table which includes this as a foreign key.

How do I do this in a create table statement?

I have tried the following:

CREATE TABLE GroupedOn(
originates_from NUMBER(38),
version NUMBER(38),
album_ID NUMBER(38),
sequence NUMBER(38) not null,
CONSTRAINT go_id_pk PRIMARY KEY(originates_from, version, album_ID),
CONSTRAINT go_id_fk FOREIGN KEY (originates_from) REFERENCES MasterTrack(track_ID),
CONSTRAINT go_id_fk FOREIGN KEY (version) REFERENCES FinishedTrack(version),
CONSTRAINT go_id_fk FOREIGN KEY (album_ID) REFERENCES Album(album_ID));


but get this error:
ERROR at line 7:
ORA-02270: no matching unique or primary key for this column-list


I guess this is because 'version' is not a candidate key, is it possible to add the whole composite primary key (from finished track) as a foreign key? If so how do I do it?

I can provide more information if neccessary...

Thanks.
Re: referencing a composite primary key as foreign key [message #340367 is a reply to message #340363] Tue, 12 August 2008 08:34 Go to previous message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Use a single constraint-line with comma-separated column lists
Previous Topic: Is it possible to call a function in SQL which calls a procedure doing inserts?
Next Topic: Difference between HOST and BIND variables
Goto Forum:
  


Current Time: Fri Dec 09 17:45:51 CST 2016

Total time taken to generate the page: 0.39037 seconds