MySQL/PHP 数据库规范化

发布于 2024-10-05 03:41:51 字数 238 浏览 2 评论 0原文

我和一群同学一起工作,创建与 php 结合使用的关系型 mysql 数据库。

我们正在尝试标准化数据库,但意见不同。当标准化和创建组中的第二个新表时,我自己认为最佳实践是将外键留在现有表中,因为新表中的唯一标识符成为新的 PK。

该小组的其余成员已被教导/认为这应该以另一种方式实现,即留下主键。

是不是只要存在关系就可以完成工作,或者是一种方法比另一种方法更正确?

预先感谢

加里

Im working amongst a group of fellow students creating relational mysql database to be used in conjunction with php.

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.

The remainder of the group have been taught/feel this should be implemented the other way, i.e. 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

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

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

发布评论

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

评论(1

新雨望断虹 2024-10-12 03:41:51

这取决于你在做什么。当您删除部分依赖项时,规则是:

   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)
  

如果您要删除传递依赖项,则:

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

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

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)

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