i have been looking around and i cannot find the correct way to do this in sql the current way i have coded it just causes my third table to fail but the rest of the code worked great up until the third table, i just need the third table to include fks from both the previous tables
first table
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS Customer;
CREATE TABLE Customer
(
CustomerNumber int NOT NULL,
CustomerName varchar(255),
CustomerAddress varchar(255),
CustomerPhoneNumber varchar(255),
JoinDate varchar(255),
PetName varchar(255),
PayScheme varchar(255),
PremiumPayDate varchar(255),
PRIMARY KEY (CustomerNumber, PetName)
);
second table
DROP TABLE IF EXISTS Policies;
CREATE TABLE Policies
(
PolicyID int NOT NULL,
PolicyNumber int NOT NULL,
PetType varchar(255),
CustomerNumber int NOT NULL,
PetName varchar(255),
EffectiveDate varchar(255),
PRIMARY KEY (PolicyID),
CONSTRAINT fk_CustomerNumber_PetName
FOREIGN KEY (CustomerNumber, PetName)
REFERENCES Customer(CustomerNumber, PetName)
);
third table
DROP TABLE IF EXISTS Claims;
CREATE TABLE Claims
(
ClaimsID int NOT NULL,
AmountForReimbursement varchar(255),
PolicyID int NOT NULL,
PetName varchar(255),
PRIMARY KEY (ClaimsID),
CONSTRAINT fk_PolicyID_PetName
FOREIGN KEY (PolicyID, PetName)
REFERENCES Policies(PolicyID), Customer(PetName)
);