So, I am modeling a database using MySQL Workbench. I have a table called Category (two fields, id and description) and a table called Event. I would like to have a column in Event that holds any number of ids from Categories (as CSV, and their order is important).
How do I represent this in MySQL Workbench (in a ER model, I mean)? Or I am doing this really wrong?
It’ll look something like this:
| ID | Descripion
| 1 | Lorem...
| 2 | Ipsum...
| 3 | Dolor...
| 4 | Sit...
| 5 | Amet...
| ID | Name | Categories
| 1 | John | 2,1,5,4
| 2 | Reese | 3,5,4
| 3 | Ben | 1,5
| 4 | Linus | 3,4,2
| 5 | Jack | 5
| 6 | Lemon | 4,5,2
(I’ve already read this: How to structure "categories" data in the database? but I am not sure I am in the same situation. My categories are more like a ‘tree’ than tags…)
For a many – many relationship you need an intermediate table which holds id’s from both tables you’re creating the relation between. On this table you can also set an ordering column which indicate how to sort your category.
and so on.
You can choose to leave a nice gap in your ordering column by a 1000+ values so you can easily put in categories between existing ordered items.