MySQL foreign key of subpart of primary key

  Kiến thức lập trình

I have this code in MySQL:

create table Expedition(
name varchar(20),
subject varchar(20),
timespan float,
location varchar(20),
represid int,
organid int,
persid int,
constraint expedition_primary primary key(name,subject,timespan,location,represid,organid,persid)  
);
create table Organiser(
organiserid int,
primary key(organiserid),
foreign key(organiserid) references Expedition(expedition_primary(organid)),  
);
create table Representator(
representatorid int,
primary key(representatorid),
foreign key(representatorid) references Expedition(expedition_primary(represid)),
);
create table county(
cnName varchar(20),
cnid int,
primary key(cnName,cnid),
foreign key(cnid) references Organiser(organiserid),
);

What I want to do is that the link between the tables Organiser and Expedition is organiserid(Organiser) -> organid(Expedition).

But the primary key of the expedition is the expedition_primary which is not only the organid but other columns as well.So how can we write in SQL that the link is only organid?Thanks.

LEAVE A COMMENT