I have a relationship between Pets, Customers, and Shipping Company Invoice and Pets has three subclasses Dog, Cat, and Bird, how should I translate that into SQL, what would the id in Invoice reference? The relationship is a many to many relation.
CREATE TABLE Dog(
id INT NOT NULL,
BirthDate Date,
Size INT,
Weight INT,
Price INT NOT NULL,
Location VARCHAR(30) NOT NULL,
Disability VARCHAR(50),
Breed VARCHAR(30)
CONSTRAINT DOG_PK PRIMARY KEY (id)
)
CREATE TABLE Cat(
id INT NOT NULL,
BirthDate Date,
Size INT,
Weight INT,
Price INT NOT NULL,
Location VARCHAR(30) NOT NULL,
Disability VARCHAR(50),
Breed VARCHAR(30)
CONSTRAINT CAT_PK PRIMARY KEY (id)
)
CREATE TABLE Bird(
id INT NOT NULL,
BirthDate Date,
Size INT,
Weight INT,
Price INT NOT NULL,
Location VARCHAR(30) NOT NULL,
Disability VARCHAR(50),
Breed VARCHAR(30),
Color VARCHAR(30),
CONSTRAINT BIR_PK PRIMARY KEY (id)
)
CREATE TABLE Invoice(
C_id INT NOT NULL,
P_id INT NOT NULL,
S_id INT NOT NULL,
CONSTRAINT INV_PK PRIMARY KEY(C_id, P_id, S_id),
CONSTRAINT INV_CID_FK FOREIGN KEY (C_id) REFERENCES Customers(id),
CONSTRAINT INV_SID_FK FOREIGN KEY (S_id) REFERENCES Shipping_Company(id),
)