简体   繁体   English

归一化和3NF

[英]Normalization and 3NF

Say I have this table, where Pizza Code is the primary key 假设我有此表,其中比萨代码是主键

披萨桌

Is this table in 3NF? 该表是3NF版本吗? If I change the Pizza Name, then surely the Price would be affected. 如果我更改披萨名称,那么价格肯定会受到影响。 But at the same time, I can see that this dependency is isolated, so my question was: 但是同时,我可以看到此依赖关系是孤立的,所以我的问题是:

  1. With the current data structure, where the dependencies of Name/Price are isolated in a separate table, can we say that this table is in 3NF? 在当前数据结构中,名称/价格的依赖关系被隔离在单独的表中,我们可以说该表位于3NF中吗?
  2. If the 2 non-key table columns were part of a larger, say, "Orders" table, then the Orders table wouldn't be in 3NF, right? 如果2个非关键表列是较大的表(例如“ Orders”表)的一部分,那么Orders表将不在3NF中,对吗?

You should ask yourself which is the meaning of PizzaCode in your table: 您应该问自己,表中PizzaCode的含义是什么:

  1. It is just a way of abbreviating the name (as it seems from the current values)? 这只是缩写名称的一种方法(从当前值看来)? In other words, is the operation of changing the name (and price) of a pizza something that can be thought of as a insertion of a new kind of pizza in place of an old one? 换句话说,更改比萨的名称(和价格)的操作是否可以看作是插入一种新的比萨代替旧的比萨?

  2. It is used to identify uniquely a certain object (the same object), that can change sometime the name and/or the price? 它用于唯一地标识某个对象( 同一对象),该对象有时会更改名称和/或价格吗?

In the first case, just get rid of it, and use PizzaName as primary key (and as foreign key in the Order table). 在第一种情况下,只需删除它,然后将PizzaName用作主键(以及在Order表中用作外键)。 The operation of changing the name of the pizza and its price will be equivalent to the addition of a new pizza and the removal of the old one (or simply you can mark the old one with an attribute available/not available if you want to keep track of all the pizzas ever sold). 更改披萨名称及其价格的操作将等同于添加新披萨和删除旧披萨(或者简单地,您可以将旧披萨标记为可用/不可用,如果要保留该属性跟踪所有售出的比萨饼)。

In the second case, use the PizzaCode as primary key and as foreign key in a table Order. 在第二种情况下,将PizzaCode用作表Order中的主键和外键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM