我们如何实施 IS-A 关系? [英] How do we implement an IS-A Relationship?
问题描述
我们通过将一个表的 PK 作为 FK 添加到另一个表来实现一对多关系.我们通过将 2 个表的 PK 添加到第三个表来实现多对多关系.
We implement an One-to-Many relationship by adding one Table's PK, as FK to the other Table. We implement a Many-to-Many relationship by adding 2 Table's PKs to a third Table.
我们如何实现 IS-A 关系?
How do we implement an IS-A Relationship ?
实体是 TECHNICIAN 和 ADMINISTRATIVE,两者都是 EMPLOYEE.我可以在表中使用一个额外的字段EMPLOYEE(id, name, surname, role, ...AdminFields..., ...TechFields...)
The Entities are TECHNICIAN and ADMINISTRATIVE which both are EMPLOYEE. I could just use an extra field in the Table EMPLOYEE(id, name, surname, role, ...AdminFields..., ...TechFields...)
但我想探索 IS-A 选项.
but i would like to explore the IS-A option.
我按照唐尼的建议做了,但没有角色字段.
I did as Donnie suggested, but without the role field.
推荐答案
我按照 Donnie 的建议做了,但没有 role 字段,因为它使事情复杂化.这是最终的实现:
I did as Donnie suggested, but without the role field, because it complicates things. This is the final implementation:
DDL:
CREATE TABLE Employee (
ast VARCHAR(20) not null,
firstname VARCHAR(200) not null,
surname VARCHAR(200) not null,
...
PRIMARY KEY(ast)
);
CREATE TABLE Administrative (
employee_ast VARCHAR(20) not null REFERENCES Employee(ast),
PRIMARY KEY(employee_ast)
);
CREATE TABLE Technical (
employee_ast VARCHAR(20) not null REFERENCES Employee(ast),
...
PRIMARY KEY(employee_ast)
);
ER图:
在这个模型中没有通用类型的员工.在这里,员工只能是管理人员或技术人员.
In this model there are no Employees of Generic Type. Here, an Employee can only be Administrative or Technical.
这篇关于我们如何实施 IS-A 关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!