I can not find out what is wrong that i am getting the error message:
Msg 1776, Level 16, State 0, Line 56 There are no primary or candidate
keys in the referenced table ‘Airplane_type’ that match the
referencing column list in the foreign key
‘FK_Airplane_make__68487DD7′. Msg 1750, Level 16, State 0, Line 56
Could not create constraint. See previous errors.
Here is that section of the query:
CREATE TABLE Airplane_type
(
make VARCHAR NOT NULL,
model VARCHAR NOT NULL,
type VARCHAR NOT NULL,
business_capacity INT NOT NULL,
economy_capacity INT NOT NULL,
range INT NOT NULL,
weight INT NOT NULL,
length INT NOT NULL,
wingspan INT NOT NULL,
PRIMARY KEY(make, model)
);
CREATE TABLE Airplane
(
airplane_ID VARCHAR(3) NOT NULL PRIMARY KEY,
make VARCHAR NOT NULL FOREIGN KEY REFERENCES Airplane_type(make),
model VARCHAR NOT NULL FOREIGN KEY REFERENCES Airplane_type(model)
);
Any help is greatly appreciated, thanks
You’ve created the primary key on two columns, shouldn’t the foreign key be created on two columns rather than individually? You can’t reference the model column in an individual foreign key because there is nothing in the original table that guarantees that model is unique.
Also, why are you using
VARCHARwithout specifying a length? Please read this blog post: