我们如何实现IS-A关系? [英] How do we implement an IS-A Relationship?
问题描述
我们通过将一个表的PK作为FK添加到另一个表来实现一对多关系。
我们通过将2个表的PK添加到第三个表来实现多对多关系。
我们如何实现IS-A关系? p>
实体是TECHNICIAN和ADMINISTRATIVE,两者都是EMPLOYEE。
我只能在表中使用一个额外的字段
EMPLOYEE(id,name,surname, role ,... AdminFields ...,... TechFields ... )
但我想探索IS-A选项。
编辑:我按照Donnie的建议,但没有角色字段。
我做了Donnie建议,但没有角色字段,因为它复杂的事情。这是最终实施:
DDL:
CREATE TABLE Employee(
ast VARCHAR(20)not null,
firstname VARCHAR(200)not null,
surname VARCHAR(200)not null,
.. 。
PRIMARY KEY(ast)
);
CREATE TABLE管理员(
employee_ast VARCHAR(20)not null参考人员(ast),
PRIMARY KEY(employee_ast)
);
CREATE TABLE技术(
employee_ast VARCHAR(20)not null参考人员(ast),
...
主键(employee_ast)
) ;
ER图表:
不是通用类型的员工。在这里,员工只能是行政或技术。
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.
How do we implement an IS-A Relationship ?
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...)
but i would like to explore the IS-A option.
EDIT: I did as Donnie suggested, but without the role field.
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 Diagram:
In this model there are no Employees of Generic Type. Here, an Employee can only be Administrative or Technical.
这篇关于我们如何实现IS-A关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!