实体关系:实线和虚线的区别

and*_*web 7 mysql entity-relationship mysql-workbench

在使用表关系时。实线和虚线的使用有什么区别?

例如

表:消息/表:用户

一个用户有 0 条或多条消息。

实线还是虚线?

小智 10

正如评论中所述,虚线表示非识别关系。

实线 => 识别关系

mySQL 文档中的定义:标识关系是指子表在没有父表的情况下无法唯一标识的关系。通常,这种情况发生在创建中间表来解决多对多关系的情况下。在这种情况下,主键通常是由两个原始表中的主键组成的复合键。

示例:我们有一个应用程序,使用此模型记录员工的到达时间:

user { id_user, name, department, job } 
arrival_log { id_user, arrival_time, department }
Run Code Online (Sandbox Code Playgroud)

arrival_log 的每一行都需要指定 user_id。如果没有 user_id,我们就无法知道谁到达了办公室。实体arrival_log是一个弱实体,因为它依赖于其他实体(用户)的存在来工作。

虚线 => 不可识别的关系。

定义:非识别性关系是指孩子可以独立于父母而被识别的关系。

例子:

flower( flower_id, flower_latin_name, flower_type_id )
flower_type( flower_type_id, name, description )
Run Code Online (Sandbox Code Playgroud)

Flower和flower_type之间的关系是非识别性的,因为每个flower_type都可以被识别而不必存在于flower表中。