我一直在搞砸 1NF [英] I keep messing up 1NF

查看:66
本文介绍了我一直在搞砸 1NF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,到目前为止我发现的关于 1NF 的最容易理解的描述是主键是唯一标识每一行的一列(或一组列).' 在 www.phlonx.com我知道冗余意味着每个键每行不应该超过 1 个值.超过 1 个值将是冗余的".对吗?

For me the most understandable description of going about 1NF so far I found is ‘A primary key is a column (or group of columns) that uniquely identifies each row. ‘ on www.phlonx.com I understand that redundancy means per key there shouldn’t be more than 1 value to each row. More than 1 value would then be ‘redundant’. Right?

我仍然设法多次搞砸 1 NF.我发布了一个关于我的在线比萨店的问题 http://foo.com披萨店这里

Still I manage to screw up 1 NF a lot of times. I posted a question for my online pizzashop http://foo.com pizzashop here

我对第二范式中的某些东西感到困惑,却发现我在 1 NF 中开始出错了.现在我想我需要 1NF 中的 3 个键来唯一标识每一行.在这种情况下,我发现 order_id、pizza_id 和 topping_id 可以为我做这些.所以这是 3 列.因为如果你想知道哪个特定的比萨是哪个,你需要知道什么 order_id 它有什么类型的比萨 (pizza_id) 以及那里有什么配料.如果您知道这一点,您可以查找所有其他内容.然而,从对上一个问题的回答来看,这似乎是错误的,因为 topping_id 转到另一个我不理解的表.这是列列表:

where I was confused about something in the second normal form only to notice I started off wrong in 1 NF. Right now I’m thinking that I need 3 keys in 1NF in order to uniquely identify each row. In this case, I’m finding that order_id, pizza_id, and topping_id will do that for me. So that’s 3 columns. Because if you want to know which particular pizza is which you need to know what order_id it has what type of pizza (pizza_id) and what topping is on there. If you know that, you can look up all the rest. Yet, from an answer to previous question this seems to be wrong, because topping_id goes to a different table which I don’t understand. Here’s the list of columns:

Order_id
订单日期
客户 ID
客户名称
电话
促销
黑名单 Y 或 N
客户地址
邮政编码
城市
电子邮件
Pizza_id
比萨名称
尺寸
Pizza_price
金额
Topping_id
Topping_name
Topping_prijs
可用
Delivery_id
Delivery_zone
Deliveryguy_id
Deliveryguy_name
交付 Y 或 N

Order_id
Order_date
Customer_id
Customer_name
Phone
Promotion
Blacklist Y or N
Customer_address
ZIP_code
City
E_mail
Pizza_id
Pizza_name
Size
Pizza_price
Amount
Topping_id
Topping_name
Topping_prijs
Availabitly
Delivery_id
Delivery_zone
Deliveryguy_id
Deliveryguy_name
Delivery Y or N

我用粗体标记了第一个连接键的 ID.它们只是未规范化的列列表.它们不是 1 张桌子或 3 张桌子或任何东西

I marked the id's for the first concatenated key in bold. They are only a list of columns, unnormalized. They're not 1 table or 3 tables or anything

推荐答案

使用 对象角色建模(用 NORMA 说)捕捉你关于设计的信息,按下按钮,它会吐出 SQL.

use Object Role Modelling (say with NORMA) to capture your information about the design, press the button and it spits out SQL.

这比让您在 1NF、2NF 等之间来回更容易.ORM 设计保证采用 5NF.

This will be easier than having you going back and forth between 1NF, 2NF etc. An ORM design is guaranteed to be in 5NF.

一些注意事项:

  • 可以拥有复合键
  • 代理键可以在概念和逻辑设计之后添加:您已经在前面添加了它们,这很糟糕.添加它们是因为 RDBMS 的性能,而不是在设计时
  • 您是否阅读了一些关于 1NF 的资料?
  • 从简单的英语和一些事实开始.这就是 ORM 对语言化的作用.
  • you can have composite keys
  • surrogate keys may be added after both conceptual and logical design: you have added them up front which is bad. They are added because of the RDBMS performance, not at design time
  • have you read several sources on 1NF?
  • start with plain english and some facts. Which is what ORM does with verbalisation.

所以:

  1. 一位顾客有很多披萨(从零到 n)
  2. 披萨有很多配料(零到 n)
  3. 客户有地址
  4. 披萨有底
  5. ...

这篇关于我一直在搞砸 1NF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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