Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from May 21 '13 at 11:19

This question came from our site for professional and enthusiast programmers.

That is exactly how a many-to-many relationship is represented in relation databases. – Jim Garrison May 21 '13 at 7:51
up vote 2 down vote accepted

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.

share|improve this answer
Thanks, I haven't really used relational databases much before so just wanted to be sure. – Dan Nixon May 21 '13 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.