Any suggestions for a db schema for storing related keywords?

主宰稳场 提交于 2019-12-06 04:12:54

If "relatedness" is a property of a pair of keywords, this schema is OK (don't forget to add UNIQUE(keyword1, keyword2))

If "relatedness" can spread a set of keywords and a set of related keywords may have additional propertirs, you may want to add a new table "Related_Set" and a M:N relationship "Keyword_Set" between keywords and sets.

If a set doesn't have any additional properties, you may just live with "Keyword_Set" table

Simplify the second table to:

CREATE TABLE relatedkeywords(
   keyword1 int(11),
   keyword2 int(11),
   FOREIGN KEY (keyword1) REFERENCES keywords(id),
   FOREIGN KEY (keyword2) REFERENCES keywords(id),
   PRIMARY KEY (keyword1, keyword2)
)

as this is one of the cases where an "artificial primary key" just makes little sense and offers no practical usefulness.

Is there a solution with just one table -

create table keywords (
   keywrd varchar (40) not null primary key,
   related_keys_csv varchar(400)  
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!