I was wondering how to prevent denormalization in this case:
Table Categories:
- id
- name
Table Category_types:
- id
- name
Association table: (category and category types are in a many-to-many relationship)
- id
- id_cat
- id_cat_type
I have a table Request
where I have to store info about the Category
of this Request
and the CategoryType
.
At the moment the schema is:
Request:
- id
- title
- desc
- id_cat
- id_cat_type
By the way I think this is a bad idea, because there is a functional dependency (I guess?) between id_cat and id_cat_type. I think I can solve this problem storing the id of the association table
Request:
- id
- title
- desc
- id_association_table
I know that splitting tables maybe would be the best option here, but I was wondering if there is some other approach to solve this kind of problems.
Thanks
-- Category CAT exists.
--
category {CAT}
PK {CAT}
-- Category type TYP exists.
--
ctype {TYP}
PK {TYP}
For each category, that category may be of more than one category type. For each category type, more than one category may be of that category type.
-- Category CAT is of type TYP.
--
category_ctype {CAT, TYP}
PK {CAT, TYP}
FK1 {CAT} REFERENCES category {CAT}
FK2 {TYP} REFERENCES ctype {TYP}
-- Request REQ is of category CAT, category type TYP.
--
request {REQ, CAT, TYP}
PK {REQ}
FK {CAT, TYP} REFERENCES category_ctype {CAT, TYP}
Note:
All attributes (columns) NOT NULL
PK = Primary Key
FK = Foreign Key