规范化 SQL 表

发布于 2024-09-14 22:25:41 字数 827 浏览 3 评论 0原文

我们可以进一步规范化这个 Sql 表吗 结构是 主键是ID、Date、NAME、Type

ID  Date          Name            Type           Value 
-----------------------------------------------------


1   08/15/2010    Rating          A+               10       
1   08/15/2010    Rating          A-               10        
1   08/15/2010    Composition     MultipleChoice   33        
1   08/15/2010    Composition     YESNO            33        
1   08/15/2010    Composition     Fillin           33        

1   08/16/2010    Rating          A+               30      
1   08/16/2010    Rating          A-               10        
1   08/16/2010    Composition     MultipleChoice   25       
1   08/16/2010    Composition     YESNO            50        
1   08/16/2010    Composition     Fillin           25      

Can we furthur Normalize this Sql Table
Structue is
Primary key is ID,Date,NAme,Type

ID  Date          Name            Type           Value 
-----------------------------------------------------


1   08/15/2010    Rating          A+               10       
1   08/15/2010    Rating          A-               10        
1   08/15/2010    Composition     MultipleChoice   33        
1   08/15/2010    Composition     YESNO            33        
1   08/15/2010    Composition     Fillin           33        

1   08/16/2010    Rating          A+               30      
1   08/16/2010    Rating          A-               10        
1   08/16/2010    Composition     MultipleChoice   25       
1   08/16/2010    Composition     YESNO            50        
1   08/16/2010    Composition     Fillin           25      

and so on

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

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

发布评论

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

评论(4

所有深爱都是秘密 2024-09-21 22:25:41

这看起来可疑地像一个组合 EAV表和历史表。它的真正目的是什么?相关表是什么?

根据给定的有限信息,您可以通过将其转换为纯历史表来对其进行标准化。 RatingComposition 不应跨行拆分,而应位于命名得体的列中。像这样:

ID  Date          Rating_A+     Rating_A-   MultipleChoicePercent  YESNOPercent FillinPercent
---------------------------------------------------------------------------------------------
1   08/15/2010    10.0          10.0        33.3                    33.3        33.3
1   08/16/2010    30.0          10.0        25.0                    50.0        25.0

.
这将允许更简单、更快:检查约束、索引和查询。

This looks suspiciously like a combination EAV table and history table. What is its true purpose? What are the associated tables?

Based on the limited information given, you would normalize it by turning it into a pure history table. The Rating and Composition should not be split across rows but should be in decently-named columns. Something like so:

ID  Date          Rating_A+     Rating_A-   MultipleChoicePercent  YESNOPercent FillinPercent
---------------------------------------------------------------------------------------------
1   08/15/2010    10.0          10.0        33.3                    33.3        33.3
1   08/16/2010    30.0          10.0        25.0                    50.0        25.0

.
This will allow for simpler and faster: Check constraints, indexes, and queries.

木槿暧夏七纪年 2024-09-21 22:25:41

你可以这样做

alt text

You could do this

alt text

庆幸我还是我 2024-09-21 22:25:41

类型和名称是否会超出特定集合?您可以将它们分解为库表并引用它们。这是我唯一能想到的。

例如,如果您的类型始终是 A1、A2、B1、B2 和 C1,您可以将它们放入一个单独的表中,然后您可以拥有一个外键,而不是不断地将 A1 输入到数据库中转到引用 A1 行的类型表。

Are types and names going to be out of a specific set? You could break them out into lib tables and reference them. That's the only thing I can think of though.

For example, if your types are always going to just be A1, A2, B1, B2, and C1, you can go make those into a separate table, and then instead of constantly entering A1 into the database, you can have a foreign key off to the table of types that references A1's row.

醉梦枕江山 2024-09-21 22:25:41

我能看到的唯一明显的事情是将名称和类型分解为单独的表,但我不能明确地说,因为我不太确定它们实际代表什么。

The only obvious thing that I can see is breaking out Name and Type to separate tables, but I can't say definitely since I'm not quite sure what they actually represent.

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