So, I’m learning (and using) a database, and so far I think I’m understanding it
Today, a question arise on the following example:
I have a table with identities (for instance, objects, which have a name and a physical description and naturally a primary auto-increment integer index). And I have identities (e.g. persons) which interact with then).
Is there any way of categorizing these identities in my a database? For instance, assume a mechanic only interacts with a very specific set of those objects (tools, car pieces, etc). So, it would make sense to restrict any search by a mechanic on the objects to that set.
Any hints on what is the natural way (if any) to approach this problem?
Thanks
You would need a table category with an id and a description
An object can have many categories and a category can have many objects. So we are facing a many to many relationship.
You need a third table, that we call a junction table. This table would have the id of the category and the id of the object.
The design would look like this
Then if you want to select the objects for a mechanic which would be the category 1 (that’s an example, you need to find the id first)
You would do a select like this
OR
Note: If a person can use many categories of tools, you will need another junction table like this