I have a structure of companies and categories organized into 3 tables:
-
empresa
- > Register of all registered companies. -
categoria
- > Registration of all registered categories. -
rel_categoria
- > Relationship betweenempresa
andcategorias
.
Where I store the data as follows in the rel_categoria
table:
id (primary_key) | id_empresa | id_categoria
And when I need to get the categories of a company, I make the selection related. Until then everything ok.
But I had the following question: Why use an extra table to save these records and I can store them in a column in the empresa
table?
Example in the empresa
table:
id | nome_empresa | categorias | [..etc..]
1 | 'Lojinha' | 1, 7, 14, 16 | ...
The only reason that comes to mind would be in the case of counting. Eg: How many companies use the X
category?
Is there any other reason? Any structural issues? Performance? Etc .. I manage the bank through MySql
and PHP
.