[英]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_id
, list_name
, user_id
, serialized_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_id
, list_name
, user_id
。
The other with a row for each list item: row_id
, list_id
, state
, profile_id
. 每个列表项都有一行:
row_id
, list_id
, state
, profile_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.