强实体vs弱实体MYSQL

强实体vs弱实体MYSQL

问题描述:

对于MySQL/SQL的分配,我需要创建2个不同的表来显示强实体和弱实体之间的差异.

For a assignment of MySQL/SQL, I need to create 2 different tables to show the difference between strong entities and weak entities.

有人可以给我看看我将如何做的一个例子吗?

Could someone show me an example of how I would do this?

我知道一个强实体可以不存在另一个实体而存在,而对于一个弱实体却不是这样.因此,例如,一个强大的实体如下:

I understand that a strong entity can exists without another entity, while the same is not true for a weak entity. So, for example, would a strong entity be as follows:

Employee(EmpNo, Name, EmpId)

?

但是我不确定如何创建一个显示差异的表.

But I am unsure how to create a table showing the differences.

想象一下Employee表中包含以下列:

Imagine the Employee table with the following columns :

EmployeeID , EmpName, EmpDept,...

EmployeeID , EmpName, EmpDept,...

Managers表将类似于:

ManagerID, EmployeeID(foreign-key),ManagerName,...

ManagerID, EmployeeID(foreign-key),ManagerName,...

现在,每个经理都是一名雇员,因此,如果Manager表中完全有一个Manager,则Employee表中将有相同的条目.

Now , each Manager is a Employee , thus if at all there is a Manager in the Manager table , there would be the same entry in Employee table.

"是" 关系被维护:Each manager is a Employee but each Employee is not a Manager

查询将类似于:

CREATE TABLE Employee
(
EmployeeID int NOT NULL,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (EmployeeID)
)

CREATE TABLE Managers
(
ManagerID int NOT NULL,
EmployeeID int NOT NULL,
..
...
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
)