I have created/am creating 3 tables: Slaves, Citizens and Incidents.
How should I go about Incident involving multiple Citizens and Slaves? Now I'm thinking about making two fields in Incidents containing list of CitizenID's and SlaveID's (SlaveID1, SlaveID2...,SlaveIDn), but it seems plain dumb.
Actually your idea doesn't sound dumb at all. You can design your Incidents
table like this:
+------------+-----------+---------+
| IncidentID | CitizenID | SlaveID |
+------------+-----------+---------+
| 1 | A | A | <-- incident #1 involved 2 citizens and 1 slave
| 1 | B | A |
| 2 | A | A | <-- incident #2 involved 2 citizens and 2 slaves
| 2 | B | A |
| 2 | A | B |
| 2 | A | B |
+------------+-----------+---------+
Now when you query for a certain incident ID you can obtain a list of all citizens and slaves involved in the incident. This is a many-to-many relationship in your database schema.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments