简体   繁体   English

如何将这些表规范化为3NF

[英]How to normalize these tables to 3NF

As part of a homework assignment I have been asked to create tables based on a case study, and all tables must be in 3NF. 作为家庭作业的一部分,我被要求根据案例研究创建表格,所有表格必须是3NF。 However, I've tried and tried to understand 3NF but I'm just not getting the hang of it and would appreciate some help. 然而,我已经尝试并试图了解3NF,但我只是没有掌握它,并希望得到一些帮助。

The requirements of the case study are for a vet clinic: 案例研究的要求是针对兽医诊所:

  1. Allow pets to be booked in for appointments 允许宠物预约进行预约
  2. Record pet treatments 记录宠物治疗
  3. Record which vet performed the treatment 记录哪位兽医进行了治疗
  4. Record items sold by the business to provide info that allows the business to produce sstock lists for purchase from the suppliers 记录企业销售的商品,以提供允许企业生产供应商采购的库存清单的信息

DOESNT NEED TO: RECORD ALL SALES 有需要:记录所有销售情况

I have the following tables so far: 到目前为止,我有以下表格:

staff: 员工:

| staff_ID | firstName | lastName | gender | address_ID | contactNumber | partTimeOrFullTime | salary |

A staff address table: 员工地址表:

| address_ID | staff_ID | number | street | city | county | postalCode | 

The vet table: 兽医表:

| staff_ID | appointment_ID |

vet_nurse: vet_nurse:

| staff_ID | appointment_ID |

An appointment table: 约会表:

| appointment_ID | customer_ID | staff_ID | patient_ID | date | time |

initial_appointment table: initial_appointment表:

| appointment_ID | customer_ID | patient_ID | diagnosis | treatment |

followUp_appointment: followUp_appointment:

| appointment_ID | customer_ID | patient_ID | diagnosis | treatment |

patient: 患者:

| patient_ID | customer_ID | animal_type | gender | weight | height | previous_Appointments | previous_Treatment |

product: 产品:

| product_ID | name | product_Category | animal | price | quantity_Available | reOrder_Level |

product_sold: product_sold:

| sale_ID | product_ID | sale_Date | 

supplier: 供应商:

| supplier_ID | product_ID | contactNumber | email |

suppliers_address: suppliers_address:

| supplierAddress_ID | supplier_ID | doorNumber | street | city | town | postalCode |

inventory: 库存:

| name | product_ID | quantity_Available | price |

Thanks! 谢谢!

I will not give you an exact answer for 2 reasons: 1) I'm too lazy to filter through all that text. 由于以下两个原因,我不会给你一个确切的答案:1)我懒得过滤掉所有的文字。 There, I said it. 在那里,我说了。 2) You wouldn't learn anything. 2)你什么都学不会。

Third normal form is about having no transitive functional dependencies. 第三种正常形式是关于没有传递性功能依赖性。 In other words, if A determines B, where B does not determine A, and B determines C, you have a transitive dependency, so B and C could be put into their own table. 换句话说,如果A确定B,其中B不确定A,而B确定C,则您具有传递依赖性,因此B和C可以放入它们自己的表中。

An example from your set could be the tables with city, state, and post code. 您的集合中的示例可以是包含城市,州和邮政编码的表格。 In real world situations, zipcode can be used to determine city and state. 在现实世界中,zipcode可用于确定城市和州。 Perhaps you could have a separate table with zipcode as the key, and city and state are the other two attributes. 也许你可以有一个单独的表,其中包含zipcode,而city和state是另外两个属性。 This can be a transitive dependency because address ID -> zip code and zip -> city, state as I said. 这可能是一个传递依赖,因为地址ID - >邮政编码和邮政 - >城市,我说的状态。

Another important thing to remember: if any fact appears twice, you can normalize even more. 另一个要记住的重要事项:如果任何事实出现两次,你可以更正常化。 For example, [city A, State B, ZipCode C] likely appears multiple times, because I'm sure you have multiple people from the same area. 例如,[city A,State B,ZipCode C]可能会出现多次,因为我确定你有多个来自同一地区的人。

EDIT After looking this over and editing it I have found a lot more things to comment on, but as this is an assignment I will give you time to think about it and come back in a few days or longer to go over it again, if you're still curious. 编辑在查看并编辑之后我发现了更多要评论的内容,但由于这是一项任务,我会给你时间考虑它,并在几天或更长时间内回来重新审视它,如果你还好奇。

EDIT 2 编辑2

I will give you suggestions table by table, but will try to limit these to just pushes in the right direction. 我将逐桌给你建议,但会尝试限制这些只是推动正确的方向。

staff - There are no transitive dependencies that jump out to me, everything in there is determined by the primary key, which is good. staff - 没有传递给我的传递依赖,其中的所有内容都由主键决定,这很好。

staff_address - Why do you have a staff_id column? staff_address - 为什么你有staff_id专栏? This is not a good idea. 这不是一个好主意。 In addition - you have a transitive dependency with the address as I mentioned already. 另外 - 你已经提到了与地址的传递依赖关系。

vet and vet_nurse - These tables have the exact same columns, so why are there two tables? vet and vet_nurse - 这些表具有完全相同的列,为什么有两个表? Certainly there's a way you can use one. 当然有一种方法可以使用。

appointment tables - Initial appointment and follow up have the same columns. appointment tables - 初始约会和跟进具有相同的列。 Again, there should be a way you can make them one. 同样,应该有一种方法可以让它们成为一体。 I will give you one direct suggestion for the appointment table: put date and time as one column, aptDate, and give it the DATETIME value type. 我将给你一个关于约会表的直接建议:把日期和时间作为一列aptDate,并给它DATETIME值类型。

patient - The customer_ID value is in the patient table, so why should it be in the others? patient - customer_ID值在患者表中,那么为什么它应该在其他人中? Also, previous appointments and previous treatments are going to be very difficult to track inside the database. 此外,以前的约会和以前的治疗将很难在数据库内跟踪。 You should see that as soon as you start inputting data. 一旦开始输入数据,您应该会看到。

product - As it is now, it doesn't seem too bad, but there are issues I will discuss later. product - 就像现在一样,它似乎并不太糟糕,但我将在稍后讨论一些问题。

product_sold - Is sale_ID unique? product_sold - sale_ID是唯一的吗? If it is, how many products can be sold in one sale? 如果是,一次销售中可以销售多少产品? This table is definitely not normalized well. 这个表肯定没有正常化。

supplier - How many products can a supplier have? supplier - 供应商可以提供多少种产品? This is your hint at how to change the product table. 这是您如何更改产品表的提示。

suppliers_address - Same issue with postalCode here. suppliers_address - 与postalCode相同的问题。 Also, why does suppliers_address point to supplier? 另外,为什么suppliers_address指向供应商?

inventory - Aren't you already tracking all of these fields in the product table (except for price)? inventory - 您是否已经在产品表中跟踪所有这些字段(价格除外)?

These are potential problems I see, but I can't in good conscience give you solutions to your assignment. 这些都是我看到的潜在问题,但我不能凭良心给你解决你的任务。 However, if this is one of your first attempts at a normalized database it's not bad at all. 但是,如果这是您在标准化数据库中的第一次尝试,那就完全不错了。

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

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