它仍然是标准化的数据库模式吗?数据库

发布于 2024-09-24 08:56:05 字数 1110 浏览 1 评论 0原文

我有以下数据库模式。

FILEGROUPBLOCK表示XML文件的对象结构。 FILE 是根。 GROUP 已 FK 到FILEBLOCK有一个FK到GROUP,另一个FK到UNIT

UNITFILE上下文中不同GROUP的“相似”BLOCK分组。

数据库目前处于3NF。但我想知道哪些UNITs属于FILE.id=1。为此,我必须进行一个连接所有 4 个表的查询。为了优化此架构,我可以创建新关系 UNIT n--FK-->1 FILE。然而,我的查询仅连接优化数据库模式上的两个表。 问题是:这个 DB(带有这个新的 FK)仍然处于 3 NF 中吗?理论怎么说?

BLOCK  n--FK-->1  GROUP  n--FK-->1  FILE
 n 
 |
 FK    
 |    
 1  
Unit

或者

            +--------+
      +-----|  File  |.....+
      |     +--------+     .
      |                    .
     /|\                  /.\
 +--------+           +--------+
 | Group  |--+     +--|  Unit  |
 +--------+  |     |  +--------+
             |     |
            /|\   /|\
           +---------+
           |  Block  |
           +---------+

I have the following db-schema .

FILE, GROUP and BLOCK represent the object structure of the XML file.
FILE is the root.
GROUP has FK to FILE.
BLOCK has the one FK to GROUP and the another one FK to UNIT.

UNIT groups "similar" BLOCKs from diffrent GROUPs in the context of FILE.

The data base is currently in 3NF. Yet I would like to know which UNITs belong to FILE.id=1. To do this yet, I have to make a query which joins all 4 tables. To optimize this schema, I can create the new relation UNIT n--FK-->1 FILE. Yet my query joins only two tables on the optimized db-schema.
And here is the question: is this DB(with this new FK) still in 3 NF ? What the theory says?

BLOCK  n--FK-->1  GROUP  n--FK-->1  FILE
 n 
 |
 FK    
 |    
 1  
Unit

or

            +--------+
      +-----|  File  |.....+
      |     +--------+     .
      |                    .
     /|\                  /.\
 +--------+           +--------+
 | Group  |--+     +--|  Unit  |
 +--------+  |     |  +--------+
             |     |
            /|\   /|\
           +---------+
           |  Block  |
           +---------+

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

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

发布评论

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

评论(3

北恋 2024-10-01 08:56:05

从提供的信息来看,这似乎是一个真正的并行层次结构。在此基础上,我相信所提议的修改模式仍将标准化为3NF。

From the information supplied, it appears that this is a true parallel hierarchy. On this basis, I believe that the proposed amended schema would still be normalised to 3NF.

み零 2024-10-01 08:56:05

在进行更改之前,尚不清楚 UNIT 表如何适应架构。

显然,进行更改后,要知道哪些单元属于文件,只需连接 FILE 和 UNIT 表即可。

由于表处于 3NF 状态,因此所有功能依赖项均由键、整个键以及除了键之外的任何内容决定(所以请帮助我 Codd),因此您必须从这个角度来看待您的模式。

鉴于现有信息,这些表很可能全部采用 3NF(BCNF 和 AFAICT 也采用 4NF 和 5NF)。

It is not clear how the UNIT table fits into the schema before you make changes.

Obviously, after you make changes, all you have to do to know which units belong to a file is join the FILE and UNIT tables.

Since tables are in 3NF when all the functional dependencies are determined by the keys, the whole keys, and nothing but the keys (so help me Codd), you have to look at your schema in that light.

Given the available information, most likely the tables are all in 3NF (and BCNF, and AFAICT in 4NF and 5NF too).

莫言歌 2024-10-01 08:56:05

我不认为你的“鱼尾纹”图支持
您的问题中概述的其他依赖项。你是怎么上来的
FILE 和 UNIT 之间的 1:Many 关系?

这些是您描述的功能依赖关系...

  • GROUP -> 文件
  • ->
  • -> UNIT

另外,我假设上述每个属性在功能上决定了一些
附加属性未出现
在任何其他函数依赖的左侧。这些将是:

  • FILE ->其他文件属性
  • GROUP ->其他组属性
  • BLOCK ->其他块属性
  • UNIT -> other-unit-attributes

从上述函数依赖关系构造一组 3NF 关系给出:

  • FileRelation: (FILE, other-file-attributes)
  • GroupRelation: (GROUP, FILE,其他组属性)
  • UnitRelation:(UNIT,其他单元属性)
  • BlockRelation:(BLOCKGROUPUNIT,其他块属性)

这几乎与您所描述的相符。

确定哪些 UNIT 实例与给定的 FILE 相关
需要将 FileRelation 联接到 FILE 上的 GroupRelation,然后将 GroupRelation 联接到
GROUP 上的 BlockRelation,然后是 UNIT 上的 BlockRelation 到 UnitRelation。

您希望通过在模型中的某个位置插入新关系来避免这种多表联接
给出从 UNITFILE 的直接映射。这种关系意味着函数
依赖项:

  • UNIT -> 文件

这看起来像您添加到“鱼尾纹”图表中的部分。添加这个引入了一个逻辑
矛盾。原始模式支持具有与以下内容相关的给定UNIT
多个 FILE 实例。如:

  • FileRelation(F1, ...)
  • FileRelation(F2, ...)
  • GroupRelation(G1, F1, ...)
  • GroupRelation(G2, F2, ...)
  • BlockRelation(B1, G1, U1, ... )
  • BlockRelation(B2, G2, U1, ...)
  • UnitRelation(U1, ...)

UNIT 实例 U1 与 FILE 实例 F1 和 F2 相关。鉴于这种情况,UNIT ->不支持FILE函数依赖
或者原始的功能依赖集不完整并且模式不完整
在3NF中。

此时需要解决现实世界是否支持FILE -> 单位
依赖与否。如果是这样,那么原始模型不属于 3NF 并且更多
架构的重新设计已按顺序进行。如果不支持依赖项,那么您最好说的是:

  • FILEUNIT -> 什么都没有

以及对应的关系:

  • FileUnit: (FILE, UNIT)

是一种反规范化,因为它的内容可能是通过现有表的功能依赖性导出的。

================================================== ====================================

编辑

基于数字对此和其他答案的评论似乎是:

  • UNIT -> FILE

是真正的函数依赖,函数依赖:

  • BLOCK -> UNIT

虽然不正确,但一定是多余的。我相信正确的 3NF 集
该模型的关系现在是:

  • FileRelation: (FILE, other-file-attributes)
  • GroupRelation: (GROUP, FILE, other-group-属性)
  • UnitRelation:(UNITFILE、其他单元属性)
  • BlockRelation:(BLOCKGROUP、 other-block-attributes)

请注意,UNIT 外键已从 BlockRelation 中删除。
这是因为 UNIT -> FILE FD 使其变得多余。这
(BLOCK, UNIT) 关系现在是通过将 FILE 上的 UnitRelation 连接到 FileRelation 来形成的
然后 FileRelation 到 FILE 上的 GroupRelation,然后 GroupRelation 到 GROUP 上的 BlockRelation。

由于未说明,原始模式不在 3NF 中
功能依赖:UNIT -> 文件。上述建议的关系集是
在3NF中。

注意:规范化模式时,需要声明每个功能依赖性
在前面。缺少一个就可能改变整个画面!

I don't think your "crows foot" diagram supports the
other dependencies outlined in your question. How did you come up
with the 1:Many relationship between FILE and UNIT?

These are the functional dependencies that you describe...

  • GROUP -> FILE
  • BLOCK -> GROUP
  • BLOCK -> UNIT

Also, I assume that each of the above attributes functionally determine some
additional attributes not appearing
on the left hand side of any other functional dependency. These would be:

  • FILE -> other-file-attributes
  • GROUP -> other-group-attributes
  • BLOCK -> other-block-attributes
  • UNIT -> other-unit-attributes

Constructing a set of 3NF relations from the above functional dependencies gives:

  • FileRelation: (FILE, other-file-attributes)
  • GroupRelation: (GROUP, FILE, other-group-attributes)
  • UnitRelation: (UNIT, other-unit-attributes)
  • BlockRelation: (BLOCK, GROUP, UNIT, other-block-attributes)

This pretty much corresponds to what you have described.

Determining which UNIT instances relate to a given FILE
requires a join of FileRelation to GroupRelation on FILE and then GroupRelation to
BlockRelation on GROUP then BlockRelation to UnitRelation on UNIT.

You want to avoid this multi-table join by inserting a new relationship somewhere in the model that
gives a direct mapping from UNIT to FILE. Such a relation implies the functional
dependency:

  • UNIT -> FILE

This looks like the bit you added to the "crows foot" diagram. Adding this introduces a logical
contradiction. The original schema supports having a given UNIT relating to
multiple FILE instances. as in:

  • FileRelation(F1, ...)
  • FileRelation(F2, ...)
  • GroupRelation(G1, F1, ...)
  • GroupRelation(G2, F2, ...)
  • BlockRelation(B1, G1, U1, ...)
  • BlockRelation(B2, G2, U1, ...)
  • UnitRelation(U1, ...)

UNIT instance U1 relates to FILE instances F1 and F2. Given this situation either the UNIT -> FILE functional dependency cannot be supported
or the original set of functional dependencies were incomplete and the schema is not
in 3NF.

At this point you need to resolve whether the real world supports the FILE -> UNIT
dependency or not. If it does, then the original model is not in 3NF and a bit more
reworking of the schema is in order. If the dependency is not supported then the best you can say is:

  • FILE, UNIT -> nothing

and the corresponding relation:

  • FileUnit: (FILE, UNIT)

is a de-normalization because its content may be derived through existing tables functional dependancies.

=================================================================================

EDIT

Based on a number of comments made to this and other answers, it appears that:

  • UNIT -> FILE

is a true functional dependency, the functional dependency:

  • BLOCK -> UNIT

while not incorrect, must be redundant. I believe the correct 3NF set of
relations for this model now is:

  • FileRelation: (FILE, other-file-attributes)
  • GroupRelation: (GROUP, FILE, other-group-attributes)
  • UnitRelation: (UNIT, FILE, other-unit-attributes)
  • BlockRelation: (BLOCK, GROUP, other-block-attributes)

Notice that the UNIT foreign key has dropped from the BlockRelation.
This is because the UNIT -> FILE FD made it redundant. The
(BLOCK, UNIT) relation is now formed by joining UnitRelation to FileRelation on FILE
then FileRelation to GroupRelation on FILE then GroupRelation to BlockRelation on GROUP.

The original schema was not in 3NF due to the unstated
functional dependency: UNIT -> FILE. The proposed set of relations above is
in 3NF.

Note: When normalizing a schema, every functional dependency needs to be stated
up front. Missing one can change the whole picture!

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