本文介绍了一张表只有一列有什么问题吗? (MSSQL服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情形:

表:


  • 员工(EmpId(PK),姓名)

  • TeamMembers(TeamId(PK),EmpId(PK))

  • Project(ProjId(PK),TeamId)

我真的想避免使用复合PK,但是我发现问题的唯一方法是创建一个只有1列TeamId(PK)的Team表(我不想存储任何与团队(而不是其成员)相关的信息)(编辑:如果创建团队表,则将TeamMeberId添加到TeamMembers表中并使其成为PK)

I really want to avoid using composite PK, but the only way I see out of the problem is creating a Team table with only 1 column TeamId(PK) (i do not want to store any info associated with the team other than its members) (EDIT: if I create a team table, i'll add TeamMeberId to TeamMembers table and make it a PK)

当前设置的另一个问题是我无法在Project表和TeamMebers表之间设置TeamId关系

Another problem with current setup is that I can't set a relationship for TeamId between Project and TeamMebers tables

我应该只创建1列Team表吗?在这种情况下,最好的方法是什么?

Should I just create a 1 column Team table? What's the best approach in this case?

只是为了清理问题,我唯一想知道的那个团队就是它的存在,没有任何其他信息

just to clear things up, the only thing I want to know about that team is its existance, no additional info of any kind

表New Design(有什么问题吗?):

Tables New Design (anything wrong with it?):


  • 员工(EmpId(PK),姓名)

  • 团队(TeamId(PK))

  • TeamMembers(TeamMemberId) (PK),TeamId(FK),EmpId(FK))

  • Project(ProjId(PK),TeamId(FK))

  • Employee (EmpId(PK), Name)
  • Team(TeamId(PK))
  • TeamMembers(TeamMemberId(PK), TeamId(FK), EmpId(FK))
  • Project(ProjId(PK), TeamId(FK))

推荐答案

如果对团队唯一感兴趣的事实是团队存在,那么 Team 表,其中只有一列: TeamId 。它可以确保 TeamMembers Project 表的引用完整性。

If the only thing interesting about a team is the fact that it exists, then there is nothing wrong with a Team table with just one column: TeamId. It ensures referential integrity from the TeamMembers and Project tables.

但是我不理解您反对复合PK。 TeamMembers 表中的列 TeamId EmpId 复合主键。

But I do not understand your objection against a composite PK. The columns TeamId and EmpId in the TeamMembers table are alreay a composite primary key.

这篇关于一张表只有一列有什么问题吗? (MSSQL服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:44