如何引用另一个表中的多行?

编程入门 行业动态 更新时间:2024-10-11 23:18:30
本文介绍了如何引用另一个表中的多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一张角色表,例如,

Let's suppose I have a table of roles, for example,

Roles ----- ID Name 0 Salesman 1 Client 2 Manager

让我们还假设这些角色不是互斥的:也就是说,一个人可以同时担任推销员,客户和经理。

Let's also suppose that these roles are not mutually exclusive: that is, a person can be a salesman, a client, and a manager all at the same time.

如果我有一个具有角色字段的 Person 表,我如何能够引用 Roles 表?

If I have a Person table with a Role field, how am I able to reference multiple rows in the Roles table?

推荐答案

您引入了一个引用了两个原始表的新表:

You introduce a new table that references both of the original tables:

CREATE TABLE PersonRoles ( PersonID int not null, RoleID int not null, constraint PK_PersonRoles PRIMARY KEY (PersonID,RoleID), constraint FK_PersonRoles_Persons FOREIGN KEY (PersonID) references Person (ID), constraint FK_PersonRoles_Roles FOREIGN KEY (RoleID) references Role (ID) )

假设多重度为 m:n ,则以上是正确的。我做出的假设(未在您的问题中列出)是一个以上的人可以推销员。

Assuming that the multiplicity is m:n, the above is correct. I made the assumption (not listed in your question) that more than one person can be e.g. a Salesman.

更多推荐

如何引用另一个表中的多行?

本文发布于:2023-10-23 14:16:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!