我应该选择这两个数据库设置中的哪一个? [英] Which of these 2 database setups should I choose?

查看:101
本文介绍了我应该选择这两个数据库设置中的哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3种类型的内容:博客,新闻稿和提醒。所有这些都有正文字段输入。博客和新闻稿有一个 title 字段,提示缺少该字段,提醒有一个小时字段博客和新闻稿缺乏。这是表格格式,所以很容易看到...

I have 3 types of content: blogs, press releases, and reminders. All of them have a body and entered by fields. The blogs and press releases have a title field, which the reminder lacks, and the reminders has an hour field, which blogs and press releases lack. This is what it looks like in tabular format so it's easy for you to see...

                   blog       press release      reminder
---------------------------------------------------
entered by field   yes        yes                yes
body field         yes        yes                yes
title field        yes        yes                --
time field         --         --                 yes

我正在创建一个名为 content 的主表, code> blogs 新闻稿 提醒。我想到了2个结构。

I'm creating a main table called content that links to the specialized tables blogs press releases reminders. I thought of 2 structures

第一结构...这是我使用的内容管理系统,但我不想盲目地跟随他们的步骤,因为我的需求不一样。将所有共享字段放在主要的 content 表中。因此, content 表将不仅具有类型类型id 链接到专用表, content 表也将具有常见的字段,例如 body 输入。其他3个表只有其唯一的字段。

First structure... This is how the content management system I use does it, but I don't want to follow in their steps blindly because my needs are not the same. Put ALL shared fields in the main content table. So the content table will not only have type and type id to link to the specialized tables, the content table will also have the common fields like body and entered by. The other 3 tables only have their unique fields.

content table    B=blogs table   PR=press releases table     R=reminders table
------------------------------------------------------------------------------
id               id              id                          id
type=B/PR/R      title           title                       hour
type id
body
entered by

第二种结构。 content 表只有类型 type id 链接到其他3个表,这意味着公共字段在3个表中重复。

Second structure. content table only has the type and type id necessary to link to the other 3 tables, This means that the common fields get repeated in the 3 tables.

content table    B=blogs table   PR=press releases table     R=reminders table
------------------------------------------------------------------------------
id               id              id                          id
type=B/PR/R      entered by      entered by                  entered by 
type id          body            body                        body
                 title           title                       hour

我应该去哪里?我认为第一个结构是更好,因为我可以搜索所有内容,无论是博客或新闻稿或提醒一个特定的单词。如果我想搜索标题,只有博客新闻稿,但...

Which should I go with? I thought the first structure is better because I can search all content whether it's a blog or press release or reminder for a specific word. I still have to look in the other tables if I want to search the title which is available only to blogs and press releases, but...

那么,哪种结构更好,我也欢迎不同于这些2的其他想法或改进。

So which structure is better, and why you think so? I'm also open to other ideas or improvements that are different from these 2.

推荐答案

第一个是更好的结构,它允许内容在内容表中具有特定组的所需或公共数据,然后在子表中具有专用数据。这也允许您添加更多类型在未来与其他要求,仍然重用内容中的常见元素,但保留任何独特的数据。

The first one is the better construct, it allows for a content to have a specific set of required or common data in the content table and then specialized data in the child tables. This also allows you to add more types in the future with other requirements that still reuse the common elements in content but retain any unique data.

另一个关键问题是,如果需要该数据,例如所有提醒需要一个小时,并且所有博客/新闻稿需要一个标题。如果它们是必需的,那么您确保这些子表将始终填充。如果他们不是那么也许你应该看看flattening结构(是的弗吉尼亚,你应该有时反标准化)。

One other key question is if that data is required, for example do all reminders require an hour and do all blogs/press release require a title. If they are required then you ensure that those child tables will always be populated. If they are not then perhaps you should look at flattening the structure (yes Virginia you should sometimes denormalize).

所以你的内容表只是变成(nn = (nn),标题(n),小时(n)输入的字符串(n = nullable),
id(nn),类型id(nn),类型(nn)我通常发现这样做的主要原因是,如果你创建的不同的数据实体是如此相似,随着时间的推移,它们可能会合并。例如,提醒在这个时候不需要标题,但在未来的可能。

So instead your content table simply becomes (nn = not null, n = nullable) id (nn) ,type id (nn), type (nn), body (nn), entered by (nn), title (n), hour (n). The main reason I usually find for doing this is that if the different data entities you are creating are so similar that over time it is possible they will merge. For example reminders at this time do not require a title, but in the future the might.

这篇关于我应该选择这两个数据库设置中的哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆