Reputation: 888
I have 3 tables involved.I would like, in the third table, to ensure that a pair of keys in this table is present in the second one.
CATEGORY
idc
-
CHILD_CATEGORY
idcc
c_category_id
-
PLACE_CHILD_CATEGORY
idp
p_category_id
p_child_category_id
I would like to know if I can create a link that ensures that.
PLACE_CHILD_CATEGORY(p_category_id, p_child_category_id) combination exists in CHILD_CATEGORY(idcc, c_category_id)
Where :
p_child_category_id == idcc
et
p_category_id == c_category_id
Any way to do that ?
Upvotes: 0
Views: 2478
Reputation: 6024
ALTER TABLE PLACE_CHILD_CATEGORY
ADD FOREIGN KEY PLACE_CHILD_CATEGORY_fk (p_category_id, p_child_category_id)
REFERENCES CHILD_CATEGORY (c_category_id, idcc)
More info: Using FOREIGN KEY Constraints; ALTER TABLE Syntax
Upvotes: 2