mysql - Should junction tables have more than one primary keys from another indentifying table? -
here's exmaple: have 3 tables. table b references table a. table b has 2 primary keys. 1 used original primary key , other 1 enforce relationship tabe a. want table b have many-to-many relationship table x. i'm adding relationship, mysql workbench added table y both of table b primary keys , 1 primary key in table x. table y has 3 primary keys.
it seems second primary key table b in junction table unnecessary since can identify table b original primary key. do still need primary key? or perhaps should not have indetifying relationship between table , b?
table , b have relationship user has many post. post must belong user. post has primary key of own, does foreign key user need primary key?
edit
here's scenario (diagram link below). tables i'm focusing on snippet, snippet_topic , tag. know, since every snippet must belong snippet_topic, has identifying relationship. used identifying relationship in mysql workbench , addded snippet_topic id primary key. afterwhich added m:n relationship tag , snippet. mysql workbench added snippet_topic id junction table (but removed it). there wrong design? or there more correct way this?
legend: yellow icon - primary key red icon - not null
each table should have 1 primary key table. if want second column in table containing values of table b primary key thats find. set second index performance if requires
Comments
Post a Comment