供应商,零件数据库,其中“供应商”表S(sno,sname,status,city)分别对应的是供应商代号,供应商名,供应商状态,供应商所在的城市。零件表P (pno,pname,color,weight,city) 表示零件号,零件名,颜色,重量及产地。
供应商和零件分别要建立一个关系模式。供应商和零件之间是一个多对多的联系,在关系数据库中,多对多联系必须生成一个关系模式,而该模式的码是该联系两端实体的码加上联系的属性构成的。若该联系的名称为SP,那么相应的关系模式是:SP(sno,pno,Qty),其中Qty表示的是零件的个数。
create table S (
sno char(5) not null unique,
status char(8) unique,
city char(20),
primary key (sno)
);
create table P (
pno char(6),
pname char (30) not null,
color char (8),
weight number (6,2),
city char(20),
primary key (pno)
);
create table SP (
sno char(5)
pno char(6),
Qty number (9),
primary key (sno,pno),
foreign key (sno) reference S(sno),
foreign key (pno) reference P (pno)
);