当前位置: 首页 > news >正文

东南大学数据库课程02-DataModel数据模型

Data Model 数据模型

目录
  • Data Model 数据模型
  • 2.1 Hierarchical Data Model
    • Basic Idea
    • Hierarchical Data Schema
    • Virtual Record
  • 2.2 Network Data Model
  • 2.3 Relational Data Model
    • Basic Idea
    • 相关术语
      • Relation,Tuple,Attribute,Column,Domain
      • Primary Key
      • Foreign Key, Reference Integrity
  • Relational Algebra关系代数
    • Projection
    • Selection
    • Union, Intersection, Set-Difference
    • Cross-Product
    • Joins
    • Division
    • Outer Joins
    • Outer Union
  • Relational Calculus 关系演算
  • 2.4 ER Data Model
    • Basic Idea
    • ER Diagram
    • Constrains
    • Advanced Topics
  • 2.5 Object-Oriented Data Model
  • 2.6 Other Data Model
  • 2.7 Summery

2.1 Hierarchical Data Model

Basic Idea

Basic Idea: because many things in real world are organized in hierarchy, hierarchical model managestodescribe real world in a tree structure.

  • Record:表示现实世界中的一个实体(老师)
  • Field:表示实体所有的属性(年龄,职称…)
  • Parent-Child relationship (PCR): the most basic data relationship in hierarchical model. It expresses a 1:N relationship between two record types

3a9a1bbf-59f3-41e8-806e-4231a870088b

Hierarchical Data Schema

  • A hierarchical data schema consists of PCRs.
  • Every PCR expresses one 1:N relationship
  • Every record type can only have one parent

c306e402-f43f-4735-955a-4f7d901245a7

Virtual Record

It’s hard to use PCR to express Multiple Parents, M:N relationship and N-ary relationship

c98421c4-893d-441b-95b1-fa68c2d0ae20

virtual record is included to solve this problem, it’s a pointer in fact

31a5c6dc-bc34-474e-9ee9-3d6f7205ae27

2.2 Network Data Model

  • Record and data items: data items are similar as field in hierarchical model, but it can be vector.
  • Set : express the 1:N relationship between two record types.
  • LINK record type: used to express self relationship, M:N relationship and N-ary relationship
  • It breakthrough the limit of hierarchical structure, so can express non-hierarchical data more easy.

0eefa67c-7279-4c1c-95e1-f1dbc9112644

d3960ee3-9888-4b43-ae5d-7e8675056aaa

2.3 Relational Data Model

Basic Idea

Basic Idea:实体用表“table”表示,实体间的关系也用表“table”表示,运算查询的结果也是表“table”,形成了一个封闭空间,可以用数学方法研究数据库问题

Advantages:

✓ Based on set theory, high abstract level
✓ Shield all lower details, simple and clear, easy to understand
✓ Can establish new algebra system——relational algebra
✓ Non procedure query language——SQL
Soft link ——the essential difference with former data models(用表表达了指针的含义)

41c01bd1-1608-4fbe-bd33-c287a83e59f3

相关术语

Relation,Tuple,Attribute,Column,Domain

68ca5345-8e8c-474c-8b7f-d6b166d4bd70

Primary Key

A set of attribute is a candidate key for a reason for:

  1. No two distinct tuples can have same values in this set of attributes(唯一性)
  2. This is not true for any subset of this set of attributes(极小性)

满足唯一性而不满足极小性的attribute集合称为Super Key【比如学号是Primary Key, 那么(学号,姓名)就是Super Key】

如果有多个PrimaryKey,则一个叫做PrimaryKey,其他成为Alternate Key

如果一个PrimaryKey包含了Rlation里的所有Attribute,这种PrimaryKey就称为ALL Key

Foreign Key, Reference Integrity

  • Foreign key : Set of attributes in one relation that is used to ‘refer’ to a tuple in another relation. (Must correspond to primary key of the second relation.) Like a ‘Logical pointer’, soft link
  • E.g. Enrolled(sid: string, cid: string, grade: string)
    ➢ sid is a foreign key referring to Students:
    ➢ If all foreign key constraints are enforced, referential integrity is achieved, i.e., no dangling references.【意味着级联删除:如果Student中的一个tuple被删除了,该tuple的sid又存在了Enrolled中,那么系统会自动把Enrolled中对应该sid的tuple也删除】

46349d8b-6790-4fec-8526-7c77bd998167

Relational Algebra关系代数

eeb1b1ca-23be-4c91-8cbe-251ae30e6e25

五种基本运算在关系代数的闭合空间中是完备的,其他运算都可以由他们导出

Intersection 交集
EXCEPT 差集(同Set-difference)
Join 连接
Division 除法

用例:

a0917677-7073-4715-97ab-3e7ff2fa92f8

Projection

cdfc0db6-cb29-406c-8fa2-5e13f0764b80

在关系代数的运算中,结果的Relation会删除重复的tuple,因为得到的Relation来看,这些tuple的含义是一致的,没有必要重复,故删除

但是实际的数据库产品往往不这么做,因为有时候用户需要用到这些重复的tuple,比如要计算水手的平均年龄,所以不删除

Selection

5c5d941e-59bc-44da-827e-7a1d8651e705

Union, Intersection, Set-Difference

19521f8f-906b-4b67-a83d-7a975d31aeed

Cross-Product

笛卡尔积

ccd40ad5-276d-49b6-b95e-0cea8ca7c922

Joins

89c6d68e-b623-44fd-83f0-461ffcfc3213

33c6c2f5-6068-4358-8819-39e879ba5eef

最常用的是 Natural Join

Division

eb3d3df6-f7b7-4ff5-92e5-921ac158ed4c

20be22a4-f046-4720-b541-0bd44cba841c

Division不是一个原子操作,但可以由原子操作导出

思路是“否定之否定”

【找到所有x,满足该x不会attach到B中的y,然后把这些x从全集中删掉】

fe4e964f-9086-44d4-9fa8-3aefa3600b6e

Outer Joins

the extension of join. In join operation, only matching tuples fulfilling join conditions are left in results. Outer joins will keep unmated tuples, the vacant part is set Null:

  • Left outer join(*⋈)

    Keep all tuples of left relation in the result.

  • Right outer join (⋈*)

    Keep all tuples of right relation in the result

  • Full outer join ()

    Keep all tuples of left and right relations in the result

f658b62f-8a62-46ec-a387-d5c5c6408032

Outer Union

  • The extension of union operation. It can union two relations which are not union-compatible.
  • The attribute set in result is the union of attribute sets of two operands
  • The values of attributes which don’t exist in original tuples are filled as NULL

55e513ac-852b-45c9-886f-6008503b3ed4

Relational Calculus 关系演算

分类:Tuple relational calculus (TRC)、Domain relational calculus (DRC)

Expressions in the calculus are called formulas【公式】. An answer tuple is essentially an assignment of constants to variables that make the formula evaluate to true

  • ppt原图

    2f11785c-098d-4a25-ab10-f46a73df1be5

    ed070991-bed8-4ffc-90e2-f01313b61675

    4b3e080d-5e8d-4c1e-8bf1-2802074d5120

    072aee2a-9710-4128-b2b0-8fffaa7c3bda

    46df8af6-1a88-4570-a656-f0fc333f23aa

    e0a6c9ab-8ce1-4adf-a961-812e706d1af5

2.4 ER Data Model

d12d1499-eff8-4213-bffe-817142b6ec5e

Basic Idea

  • Entity(实体):现实世界的事物,用一组Attribute表示(员工)

  • Entity Set(实体集):相似实体的集合(全体员工)

    • 所有实体有相同的attribute

    • 每个实体有一个key

    • 每个attribute有一个domain

    • 允许attribute是复合类型或者多值【突破了1NF(一范式)】

      允许了复合类型

      允许了复合类型

  • Relationship:两个或者多个实体间的关联【e.g Attishoo works in Pharmacy department】

    • Relation也可以有attribute
  • Relationship Set:相似关系的集合

    • An n-ary【n元的】 relationship set R relates【关联】 n entity sets E1...En; each relationship in R involves entities e1, ..., en
    • Same entity set could participate in different relationship sets, or in different “roles” in same set.

ER Diagram

6300ea4d-8ba3-4beb-a4a3-0ae09cc11519

Constrains

11474bbf-da08-455a-bce4-3b964219f0c6

4e123203-00de-4e4b-95f3-f25105538c05

Advanced Topics

  • Weak Entity【职工和家属,家属依附于职工而存在,家属就是弱实体】

    QQ截图20220917122141.png

  • Specialization and Generalization【类似于面向对象中的继承】

  • Aggregation【聚集】:允许我们把关系集视为对象集来加入另一个关系集

    aggregation:把合作这个relationship看做是实体,让它和其他实体发生联系

    aggregation:把合作这个relationship看做是实体,让它和其他实体发生联系

  • Category:允许我们把不同类型的实体加入同一个实体集,这样的实体集又叫做杂交集【hybrid entity set】

2.5 Object-Oriented Data Model

  • The shortage of relational data model

  • Break through 1NF

  • Object-Oriented analysis and programming

  • Requirement of objects’ permanent store

    考虑的是如何将对象永久存储,在需要的时候再调入内存

  • Object-Relation DBMS

    允许用户定义自己的数据类型,突破了1NF,但不能称之为面向对象数据库模型

  • Native (pure) Object-Oriented DBMS

    纯面向对象模型几乎消亡

2.6 Other Data Model

5210a5d5-5f54-47bb-883f-8ab8d52060d0

2.7 Summery

769ad3a2-84d8-467c-861e-1760d34a6f2b

http://www.wxhsa.cn/company.asp?id=4714

相关文章:

  • Torch核心数据结构Tensor(张量)
  • vue - 进阶
  • 读书笔记:为什么你的数据库有时不用索引?一个关键参数告诉你答案
  • MacOS升级15.2后的问题(一):安装第三方下载的软件,提醒文件已损坏
  • Playwright MCP浏览器自动化教程
  • 故障分析:ORA-00900 修改props$中字符集导致
  • 实用指南:Flask学习笔记(三)--URL构建与模板的使用
  • Ollama + Python 极简工作流
  • 快速搞定Dify+Chrome MCP:打造能操作网页的AI助手
  • HCIP——RSTP
  • ORA-01555系列:三、ORA-01555总结与高级优化建议
  • Unstable Twin - TryHackMe
  • 单片机实现挡位调节
  • 完整教程:从 WildCard 野卡到 gptplus.plus:一次解决 OpenAI 支付难题的实战复盘,轻松搞定Gpt充值
  • 阿里 Qoder 新升级,Repo Wiki 支持共享、编辑和导出
  • 长城杯WriteUp
  • vite取别名@
  • JavaScript数据网格方案AG Grid 34.2 发布:更灵活的数据结构、更流畅的大数据交互与全新 UI 体验
  • BOE(京东方)IPC电竞嘉年华盛典圆满收官 第三届无畏杯总决赛引领电竞生态发展热潮
  • P1886 滑动窗口 /【模板】单调队列
  • kingbase金仓数据库docker部署完整步骤
  • glTF/glb功能、应用和 5 个基本最佳实践
  • AI 应用开发,不就是调个接口么?
  • 95.费解的开关
  • godot4人物移动一段距离后随机旋转代码,(死循环)
  • Spotify 音乐ML练习数据集含158 个特征,11
  • abc423
  • AI辅助分析HP DL360 GEN7 服务器安装USB3扩展卡
  • 最新药物数据集下载:来自Drugs
  • 【VPX361】基于3U VPX总线架构的XCZU47DR射频收发子模块