[英]Best Way to Store Searchable References to Rows in Other Table in MySQL
I would really appreciate advice on database design for MySQL. 我非常感谢有关MySQL数据库设计的建议。 I'm making a 2 table database where the COLLECTIONS table has the names of books in a particular series.
我正在建立一个2表数据库,其中COLLECTIONS表具有特定系列中的书名。 Each book has a "recommended reading" list referring to books that aren't in the COLLECTIONS table.
每本书都有一个“推荐读物”列表,该列表指向不在COLLECTIONS表中的书。 The 2nd table, READING, has a row for each book in a "recommended reading" list.
第二个表READING在“推荐阅读”列表中为每本书都有一行。
I want to have a column in the COLLECTIONS table where I can have a list (array?) of the row ids from the READING table. 我想在COLLECTIONS表中有一列,在其中可以有READING表中的行ID的列表(数组?)。 I want to have a column in the READING table where I have a list (array?) holding the ids of each row in the COLLECTIONS table where that book is mentioned.
我想在READING表中有一列,其中有一个列表(数组?),其中保存着提到该书的COLLECTIONS表中每一行的ID。
My idea is when a query grabs a row from COLLECTIONS it can quickly search the stored list and grab each row from READING that is there. 我的想法是,当查询从COLLECTIONS抓取一行时,它可以快速搜索存储的列表,并从那里的READING抓取每一行。 Also, when a query grabs a row from READING it can quickly search the stored list of id numbers and grab each row from COLLECTIONS.
同样,当查询从READING抓取一行时,它可以快速搜索存储的ID号列表,并从COLLECTIONS抓取每一行。
So each table would have a column for storing id numbers from the other table. 因此,每个表都有一列用于存储另一个表的ID号。 Should these columns be TEXT and have:
这些列应为TEXT并具有:
3, 16, 56
Or is there a better way to store this? 还是有更好的方法来存储它? I appreciate suggestions on this.
我对此表示赞赏。
Dont use array create a relational table and keep 3NF 不要使用数组创建关系表并保留3NF
Collections (collection_id, ... )
Reading (reading_id, .... )
Collection_Reading (collection_id, reading_id)
That way you only need update one table Collection_Reading
when something change instead of update 2 arrays. 这样,您只需在发生某些更改时更新一个表
Collection_Reading
,而不是更新2个数组。 Also 也
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.