简体   繁体   English

我应该如何在数据库中构造这些数据?

[英]How should I structure this data in my database?

So I've got this feature I'm building to allow users to save profile's to a list. 因此,我已经建立了此功能,以允许用户将个人资料保存到列表中。 Kind of along the lines of a playlist with a name of the list, the user's id and the unique profile data as an array with both the profile id and the state's abbreviation that the profile is in. 播放列表的种类,带有列表的名称,用户的ID和唯一的配置文件数据,作为一个数组,同时包含配置文件ID和配置文件所在州的缩写。

More specifically I'm wondering whether or not I should have the list be a single row in a table with these columns: list_id , list_name , user_id , serialized_list . 更具体地说,我想知道列表中的单行是否应包含以下列: list_idlist_nameuser_idserialized_list

Where the serialized_list column is an array containing the state key and the profile id. 其中serialized_list列是包含状态键和配置文件ID的数组。

The other alternative I came up with is something like having two tables. 我想到的另一个选择是拥有两个表。 One with the columns: list_id , list_name , user_id . 其中一列: list_idlist_nameuser_id

The other with a row for each list item: row_id , list_id , state , profile_id . 每个列表项都有一行: row_idlist_idstateprofile_id

I'm kind of a database n00b, so I'm not entirely sure what considerations should even be made, but I guess I'm asking which of these (or another alternative) would be better with respect to speed and maintainability? 我有点像数据库n00b,所以我不完全确定应该考虑哪些因素,但是我想我想问一下其中哪一个(或其他选择)在速度和可维护性方面更好?

I always find it best to do it the second way you mentioned as you directly call the rows rather than have to strip out the serialized list. 我总是发现最好用您提到的第二种方法来做到这一点,因为您直接调用行而不是必须除去序列化列表。 If you are going to be looking up profile_id and state from the serialized list, you can easily have that within the same query doing it the second way. 如果要从序列化列表中查找profile_id和state,则可以轻松地在同一查询中以第二种方式进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该如何构建数据库? - How should I structure my database? 我应该如何构造我的MySQL数据库? - How should I structure my MySQL database? 我应该如何构建我的数据库以避免这个问题? - How should I structure my database to avoid this problem? 如何在Android应用程序中构造数据库访问方法? - How should I structure database access methods in my Android app? 我应该如何设计这个问题的数据库结构? - How should I design the database structure for this problem? 我应该如何构建我的 MongoDb 数据库? 大量的小文件或嵌入较少的文件? - How should i structure my MongoDb database? A lot of small documents or embedded fewer documents? 我应该如何设计/构建数据库和ActiveRecord关联? has_many:通过吗? - How should I design/structure my database and ActiveRecord associations? has_many :through? 我应该如何优化/构建数据库以收集网上商店的价格发展信息? - How should I optimize/structure my database for collecting webshop price development? 我应该在数据库中分离冗余数据吗? - Should I separate redundant data in my database? 数据库设计-我的数据应该有多精细? - Database design - How granular should my data be?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM