I am creating a many-to-many relationship between the MEMBER and INTEREST tables.
Do I need a column in the intersection table that represents a vote of “Yes”, or is the mere fact that a record exists in this third table enough to show a Member has a given Interest.
Here is my preliminary table…
MEMBER_INTEREST
----------------
- id
- member_id
- interest_id
- value ??????
First off, such a table is called a Junction table, not an intersection table. It’s good to use the correct terms when you can so people know what you’re talking about. (an intersection in databases is when you query two tables and intersect the result, i.e., all rows that are in query A that are also in query B. I guess you can see why you calling something an intersection table can be confusing to others).
It depends on the kind of interest shown. If it’s purely a question of interested yes or no, then I would say the mere existence of the record indicates interest. If there is some sort of quantifier involved (somewhat interested, interested, very interested, etc), you would need an extra field.
Also, you don’t need an id column in that table, since the combination of member_id and interest_id form a natural primary key.
TL;DR you only need member_id and interest_id in that table.
[quote=“rpkamp, post:2, topic:116221”]
First off, such a table is called a Junction table, not an intersection table. [/quote]that’s a bit harsh
it’s called a relationship table, because it is necessary to implement a many-to-many relationship
i’ve also heard a half dozen other names for it – association table, linking table, intersection table, as well as all of the other variants listed in both the web pages that you linked to
interestingly (to me, anyway, because i learned database and writing queries on IDMS, before commercial relational databases), the “junction” terminology dates back to CODASYL standards, when it was used for exactly the same purpose – to implement m-m relationships
It’s A LOT easier to reference a record in a Junction/Reference/Intersection table by a unique Integer ID versus several fields.
My overall approach is this…
Nearly every table has an AutoIncrement ID field as the PK. Where practical, I use Natural Keys as backup UK’s. That way you have the best of both worlds.
Anyways, this whole topic is another thread - just saying…
[quote=“mikey_w, post:8, topic:116221”]It’s A LOT easier to reference a record in a Junction/Reference/Intersection table by a unique Integer ID versus several fields.[/quote]only if it has child tables
which so few of them do
[quote=“mikey_w, post:8, topic:116221”]Anyways, this whole topic is another thread - just saying…
[/quote]
i encourage you to start it, because i shall defend this particular point vigorously
i encourage you to start it, because i shall defend this particular point vigorously
[/quote]
I like an easy-to-read ID for every record, unless it is maybe a lookup table with 5 entries.
AutoIncrement/ID fields add virtually no overhead, but do add value to any table, e.g.
1.) Easy-to-read identifier when visually scanning the table
2.) Unique Key for tables that don’t have one (e.g. Intersection Tables with no Unique Key)
3.) Guaranteed to be unique which isn’t always the case with Natural Keys
4.) Less likely to be changed on the backend than a Natural Key which may change
I never said that I don’t like or favor Natural Keys, because I do. But there is virtually no harm in have a defacto AutoIncrement ID on most tables in addition to the use of Natural Keys.
And most importantly, the ID that I added in my Intersection Table meets “my” needs/desires so it is indeed a good choice.