Sorry is this seems a stupid question, but I have a table of server addresses and a second table with a list of hardware devices which use the addresses, it is possible for multiple devices to use the same server address and a device to use multiple server addresses, so there is a many to many mapping between them. I am a little confused how I can represent the relationship between them in SQL, so far I am using a third table with the primary keys from the address table and device table and perform two joins in the query, but I'm not sure if this is the best way.
2 Answers
You are doing the right way,
In many-to-many relation your must have a third table mapped by the ID of the two other tables. The two Id must be foreign key, and the association of the two is the primary key of your association's table
You can also store in this table the information that are related on the relation.
-
Thanks, I haven't really used relational databases much before so just wanted to be sure.– Dan NixonCommented May 21, 2013 at 9:20
You can create another table between these two and put many to this table from both sides. This table will have it's ID and foreign IDs' from another two tables.