Do inherited keys need some kind of creation in SQL creation scripts?

293 views Asked by At

I'm trying to represent inheritance (I know) in creating a database. I have it figured out, but I'm not sure if I need to represent the PK that my tables inherit when creating tables.

I have a FoodClass relation with the PK FoodClassID from which DonorFood and CharityFood inherit. Do I need to do anything other than just name the PK FoodClassID in each table?

1

There are 1 answers

3
nvogel On BEST ANSWER

I expect you'll want a combination of PRIMARY KEY and FOREIGN KEY. Example:

CREATE TABLE DonorFood
(FoodClassID INT NOT NULL
 FOREIGN KEY REFERENCES FoodClass (FoodClassID)
 PRIMARY KEY,
... other columns    );