简体   繁体   中英

Best Way to Store Searchable References to Rows in Other Table in MySQL

I would really appreciate advice on database design for MySQL. I'm making a 2 table database where the COLLECTIONS table has the names of books in a particular series. Each book has a "recommended reading" list referring to books that aren't in the COLLECTIONS table. The 2nd table, READING, has a row for each book in a "recommended reading" list.

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. 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.

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. 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.

So each table would have a column for storing id numbers from the other table. Should these columns be TEXT and have:

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

   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. Also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM