简体   繁体   English

MySQL / PHP数据库规范化

[英]MySQL/PHP Database Normalisation

Im working amongst a group of fellow students creating relational mysql database to be used in conjunction with php. 我在一群同学中工作,创建与php结合使用的关系mysql数据库。

We are attempting to normalise the database and are differing in opinion. 我们正在尝试规范化数据库,并且意见不一。 When normalising and creating a new table two of the group, myself included feel the best practice is for the foreign key to be left behind in the existing table as the unique identifier in the new table becomes the new PK. 在归一化并创建该组中的两个新表时,我本人感到最佳做法是将外键留在现有表中,因为新表中的唯一标识符成为新PK。

The remainder of the group have been taught/feel this should be implemented the other way, ie the primary key is left behind. 已经教过/感觉到该组的其余部分应该以另一种方式来实现,即主键被遗忘了。

Could it be the case as long as a relationship is present it will do the job, or is it the case one method is correct over the other. 只要存在关系就可以完成任务,或者一种方法比另一种方法正确。

Thanks in advance 提前致谢

Gary 加里

This depends on what you are doing. 这取决于您在做什么。 When you are removing a partial dependency then the rule is: 当删除部分依赖项时,规则是:

r = (A, B, C, D)
   where
      A and B makes a composite primary key and
      C is dependent on A 
   then
      r1 = (A, C)
      r2 = (A, B, D)

If you are removing a Transitive dependency then: 如果要删除传递相关性,则:

r = (A, B, C)
     where A is the primary key and C is dependent on B then

     r1 = (A, B)
     r2 = (B, C)

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

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