mysql - SQL Many-To-Many relationships -
question
is there way have many-to-many relationship among 3 tables without use of automatic incrementers (usually id), or id's required this?
why ask
i have 3 relative tables. since one-to-one relationships seem can't happen directly, made 4th one-to-many relationships other 3 tables. however, since there's still primary key each table, value can used once in table, don't want happen.
what have
- connectors has multiple pockets have multiple pins.
- the 4th table connectorfullinfo screenshot http://i60.tinypic.com/2exy8og.jpg
there no requirement table have "automatic incrementer" primary key.
but, familiar pattern add surrogate id column primary key on entity tables. "ideal" primary key "anonymous" (carry no meaningful information), "unique" (no duplicate values), "simple" (single column, short simple native datatype), ...
there couple of schools of thought on whether it's idea introduce surrogate key. note there have been later burned decision use natural key rather surrogate key. , there haven't yet been burned decision.
in case of "association" tables (tables introduced resolve many-to-many relationships), combination of foreign keys can used primary key. this.
but, if association table turns out entity table, it's own attributes, introduce surrogate id column. example, association between person , club, person can member of multiple clubs, , club can have multiple members...
club +--< membership >--+ person when start adding attributes membership (such status, date_joined, office_held, etc... @ point membership isn't association table; it's turning entity. when suspect association entity, i'll add surrogate id column.
the other case add surrogate id column association table when want allow "duplicates", want allow multiple associations. in case, introduce surrogate id column.
Comments
Post a Comment