强实体vs弱实体MYSQL [英] Strong vs Weak entities MYSQL

查看:517
本文介绍了强实体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)
)

这篇关于强实体vs弱实体MYSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆