sql - ERROR: there is no unique constraint matching given keys for referenced table "fruit" -
create table gruppelærer( brnavn varchar(8), emnekode varchar(8), år int, vh char(4), antallgr int, constraint larer_id primary key(brnavn, emnekode, år, vh) ); create table søknad( brnavn varchar(8), emnekode char(4), år varchar(8), vh int, antallgr int, prioritet int, foreign key (brnavn, emnekode, år, vh, antallgr) references gruppelærer(brnavn, emnekode, år, vh, antallgr), unique (brnavn, emnekode, år, vh, prioritet) );
error:
there no unique constraint matching given keys referenced table "fruit"
why not work?
either, need remove [vh]
field primary_key
or add in foreign_key
:
create table fruit( fruitname varchar(128), fruitid varchar(8) not null, yearplanted int, vh char(4), numberoffruits int, constraint fruit_id primary key(fruitname, fruitid, yearplanted, vh) ); create table instore( fruitname varchar(8), fruitid int, yearplanted char(4), quantity int, foreign key (fruitname, fruitid, yearplanted, vh) references fruit(fruitname, fruitid, yearplanted, vh), unique (fruitname, fruitid, yearplanted, quantity, vh) );
Comments
Post a Comment