假设我有一张角色表,例如,
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.
更多推荐
如何引用另一个表中的多行?
发布评论