I have made a composite key as a primary key for table Airlines. And I want to use that primary key as a foreign key for table Flights. With that what I want is to have Flights that
- that either are not related to Airlines,
- or if they are, they need to have both columns of the composite key.
Below are tables:
CREATE TABLE Airlines (
name char(32),
country char(32),
PRIMARY KEY (name, country)
);
CREATE TABLE Flights_operate (
num integer PRIMARY KEY,
dept timestamp,
arr timestamp,
name_Airlines char(32),
country_Airlines char(32),
CONSTRAINT FK
FOREIGN KEY (name_Airlines, country_Airlines) REFERENCES Airlines (name, country)
);
I tried using CONSTRAINT
but it doesn't seem to do the trick.
I can still insert rows with a name_Airlines
and without a country_Airlines
like so:
image
What should I do?