在这种情况下我应该进行反规范化吗?

发布于 2024-09-09 09:03:44 字数 326 浏览 5 评论 0原文

情况是这样的:

[职位]属于一个[职位类别],而[职位类别]又属于一个[行业]

所以,我最初的设计是这样的: 工作有一个 fk 来查找工作类别,工作类别有一个 fk 来引用行业。 但问题是,当我想知道该工作属于哪个行业时,我需要找到该工作类别,并根据该工作类别id来查找行业表。所以,我正在考虑进行非规范化。

但我有两种方法可以做到这一点,我在想哪一种更好。首先,将所有内容,包括职位类别、行业记录在同一个地方(职位表)。

另一种做法是Job仍然引用Job Category,但Job Category有一个字段来存储行业信息。

您认为哪种方法更好?谢谢。

Here is the situation:

[Job] belongs to one [Job Category], which [Job Category] is belong to one [Industry]

So, my initial design is like that:
A Job have a fk to find the Job Category, and a Job Category have a fk to reference to Industry.
But the problem is when I want to know the job is belong to which industry, I need to find the job category, and based on the job category id, to look back the industry table. So, I am thinking doing de-normalization.

But I have two approach to do so, I am thinking which is a better one. First, records all stuffs, including the Job Category, Industry in the same place(the Job table).

Another approach is Job still reference to Job Category, but Job Category have a field to store the industry information.

Which approach you think it is better? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小兔几 2024-09-16 09:03:44

你的第二种方法很好。你所描述的问题,即为给定的工作找到一个行业,实际上不是问题。请参阅以下结构:

Table jobs
ID PK
REF_CATEGORY FK

Table jobcategories
ID PK
REF_INDUSTRY FK

Table industries
ID PK

现在,要获得给定工作的行业:

SELECT j.ID, i.ID
FROM jobs j
JOIN jobcategories c ON j.REF_CATEGORY = c.ID
JOIN industries i ON c.REF_INDUSTRY = i.ID

有时有充分的理由进行非规范化,但在这种情况下您不应该。如果将 JOB、JOBCATEGORY 和 INDUSTRY 放在一张表中,则可能存在一个职位类别属于多个行业的风险,从而破坏了 1-n 关系。

Your second approach is good. The problem you describe, getting an industry for a given job, is actually not a problem. See the following structure:

Table jobs
ID PK
REF_CATEGORY FK

Table jobcategories
ID PK
REF_INDUSTRY FK

Table industries
ID PK

Now, to get the industry for a given job:

SELECT j.ID, i.ID
FROM jobs j
JOIN jobcategories c ON j.REF_CATEGORY = c.ID
JOIN industries i ON c.REF_INDUSTRY = i.ID

There are good reasons to sometimes denormalize, but in this case you shouldn't. If you put the JOB, JOBCATEGORY and INDUSTRY in one table, you risk having a jobcategory belonging to multiple industries, thus breaking your 1-n relation.

沧桑㈠ 2024-09-16 09:03:44

但这种参照关系始终存在。如果您仅将行业表和工作类别表用于工作详细信息,那么您可以考虑反规范化。但如果这些表还连接到其他一些数据/表,则应审查标准化方案。去规范化不应该孤立地进行。而且,我不认为连接 RDBMS 上的三个表有很高的开销。

But this kind of referential relations are always there. If you are using the Industry table and the job category table only for the Job details, then you can think of de-normalisation. But if these tables are also connected to some other data/tables, the normalisation scheme should be reviewed. De-normalisation should not be done in isolation. And, I don't feel you are having a very high overhead to connect three table on RDBMS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文