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

103 - Lecture 1

Introduction to Database

一、Introduction to Database Systems

1. 数据的定义

What is Data?

EX: data could be a docx file storing your project status report;

        data could be a spreadsheet containing information

• 数据只有在设计的场景中才有意义。(designed scenario)

• 数据需要能够被创建、修改和访问。(to be created, modified, and accessed)

2. 数据库的定义

What is a Database?

(1) Database

• 数据库是“有组织的数据集合,结构化、便于快速搜索和检索”。

“organized collection of data, structured for ease and speed of search and retrieval.”

(2) Database Management System

• 数据库管理系统 (DBMS) 是一种软件,允许用户存储、检索和更新数据库中的数据。

3. 数据库的应用

Database Applications

Database applications include mobile payment, hotel booking websites, online game data storage, and healthcare.

4. DBMS 环境的组成部分

Components of the DBMS Environment

(1) Hardware

硬件:运行 DBMS 的计算机。

(2)Software

软件:包括 DBMS、应用程序(如支付宝)和操作系统。

application programs (e.g., Alipay), and the operating system.

(3)Data

 数据:包括操作数据和元数据。( operational data and metadata.)

(4)Procedures

程序:设计和使用数据库的规则和指令。

instructions and rules governing the design and use of the database.

(5)People

人员:包括数据库设计人员、终端用户、开发人员和管理员。

database designers, end users, application developers, and database administrators.

5. DBMS 功能

DBMS Functions / Must Haves

(1). 允许用户存储、检索(retrieve)和更新数据。

(2). 系统目录:包含模式、用户、应用程序等的元数据。

System catalog: holds data about schemas, users, applications, etc., also known as metadata.

(3). 原子性(Atomicity):确保操作要么完全执行,要么不执行。

(4). 并发控制(concurrency control):确保多个用户更新时数据库的正确性。

(5). 数据恢复(data recovery):在数据库损坏时进行恢复。

(6). 权限控制(Access control):确保只有授权用户(authorized users)可以访问数据库(DB).

6.数据模型

Data Models

• 数据可以有不同的结构模型,如关系模型、层次模型、网络模型等。

 relational data model, hierarchical model, and network model.

关系模型:基于数学概念的表格形式,具有列和行。

实体关系模型:常用于教学数据库结构的基础。

Entity-Relationship Model: Commonly used to teach database structure basics.

•Graph model:uses graph structures for semantic queries with nodes,edges

 二、Relational Model

1. Terminologies

关系:相当于表格,由列和行组成。

Relation: A table with columns and rows.

属性:关系中的列。

Attribute: A named column of a relation.

:属性的允许值集合,每个属性有一个域,例如,Department 的域可能包括 Marketing、Accounts 和 Personnel。

Domain: The set of allowable values for attributes.

元组:关系中的一行,代表一个实体实例。

Tuple: A row in a relation, representing an instance of an entity.

基数:关系中的行数。

Cardinality: The number of tuples in a relation.

:关系中的属性数量。

Degree: The number of attributes in a relation.

2. Properties of Relations

• 每个关系的名称在数据库模式(schema)中是唯一的。

• 每个单元格只包含一个原子值。( atomic value)

• 关系中没有重复的元组。

No duplicate tuples in a relation.

• 一个属性的所有值必须属于同一个域,这意味着它们的数据类型和约束条件相同。

• The order of attributes has no significance. 

• The order of tuples has no significance.

三、Relational Keys

 在一个关系中,不允许有重复的元组。 因此,我们需要能够识别一个或多个属性(称为关系键),以唯一地标识(uniquely identified)关系中的每个元组。

超键(Superkey):唯一标识关系中元组的属性或属性组合。

a superkey may contain additional attributes that are not necessary for unique identification

候选键(Candidate key):最小(minimal)的超键,且不包含不必要的属性。

Thee may be several candidate keys for a relation

主键(Primary Key):候选键中选定用于唯一标识元组的键。

candidate keys = primary key + alternate keys

A relation can only have one primary key

外键(Foreign Key):引用另一个关系中候选键的属性。

Foreign Key: An attribute or set of attributes in one relation that references the candidate key of another relation.

• when a key consists of more than one attribte, we call it a composie key.

从图片中的提示可以看出,staff_id 是主键

Finding Candidate Key

• 不能仅依靠(based solely)表中的数据来推断候选键。

• 通常(more often than not),一个关系的实例只包含所有可能值的一个小子集。

示例

• 表 Queue 中的 queue_no 值会重复使用,例如从 A1 到 A99,再重置(reset back)到 A1。

• 因此,仅靠 queue_no 可能不足以唯一标识一条记录。

Example

CREATE TABLE Branch (

    branchNo CHAR(4) PRIMARY KEY,

    street VARCHAR(100),

    city VARCHAR(25),

    postcode VARCHAR(7) UNIQUE

);

• branchNo 是主键,而 postcode 是唯一键。

branchNo is the primary key, and postcode is a unique key.

EX:

外键是一种约束,用于确保一个表中的某些值必须与另一个表中的主键或候选键相对应,以维护数据的一致性和完整性。例如:

• 如果 staff 表中的 branchNo 是 Branch 表的外键,那么 staff 表中 branchNo 列的值必须在 Branch 表的 branchNo 列中存在。

• 这确保了 staff 表中引用的 branchNo 始终是有效的,避免数据引用错误。

http://www.lryc.cn/news/478081.html

相关文章:

  • Ubuntu 20.04禁用或者移除 cloud-init
  • DevOps开发运维简述
  • C++之list的使用
  • nginx配置代理地址
  • 国际版JAVA同城打车源码同城服务线下结账系统源码适配PAD支持Android+IOS+H5
  • AndroidLab:一个系统化的Android代理框架,包含操作环境和可复现的基准测试,支持大型语言模型和多模态模型。
  • Java--正则表达式入门指南
  • 阿里云服务器 篇十(加更二):自动定时备份CSDN博客内容:更新文件最后修改时间,以在个人博客正确展示最近更新
  • Python编程探索:从基础语法到循环结构实践
  • 今天要重新认识下注解@RequestBody
  • 北斗有源终端|智能5G单北斗终端|单兵|单北斗|手持机
  • 【题解】—— LeetCode一周小结44
  • faiss 用于检索10亿向量(维度768)的方法
  • sql专题 之 常用命令
  • Kubernetes Extended Resource 扩展资源使用简介
  • 基于STM32的天气时钟项目教学
  • 神经网络进行波士顿房价预测
  • C++builder中的人工智能(7)如何在C++中开发特别的AI激活函数?
  • 更改lvgl图片的分辨率(减少像素)达到减小内存占用的目的
  • python的socket库的基本使用总目录
  • golang学习3
  • Python解力扣算法题(六)(详解+注释)
  • 【C++】继承和多态常见的面试问题
  • 入门网络安全工程师要学习哪些内容(详细教程)
  • 【游戏引擎之路】登神长阶(十二)——DirectX11教程:If you‘re going through hell, keep going!
  • Python列表(一图秒了)
  • 雷池社区版 7.1.0 LTS 发布了
  • 推荐一款功能强大的数据库开发管理工具:SQLite Expert Pro
  • 动态规划 之 路径问题 算法专题
  • 从office套件接入GPT4谈自动化测试的前景