I have Entity Relationship Model (ERD) where entities IndividualCategory
and TeamCategory
relate to entity Category
. Now I want to create tables in Oracle DB. I started like this:
CREATE TABLE Category(
category_id INT PRIMARY KEY,
...
);
CREATE TABLE Individual_category(
category_id INT CONSTRAINT fk_cat_indivcat REFERENCES Category(category_id),
...,
CONSTRAINT pk_indivgamecat PRIMARY KEY (category_id)
);
CREATE TABLE Team_category(
category_id INT CONSTRAINT fk_cat_teamcat REFERENCES Category(category_id),
...,
CONSTRAINT pk_teamcat PRIMARY KEY (category_id)
);
This combination of Foreign key and Primary key constraints assures that for every Individual_category
there will be corresponding record in Category
"super" table (or "parent" table ?). And there will be only one IndividualCategory
record for particular Category
record. Same for Team_category
.
To enforce inheritance I need one more constraint: A constraint that assures that for every record in Category
there will be either record in IndividualCategory
(X)OR a record in TeamCategory
but not both.
How do I create such constraint ?
EDIT: This is what I meant by 'inheritance in E-R model'. This is from my DB teacher's slides (they call it "Entity sub-type" there but they sometimes call it just inheritance):