【数据库系列】之《设计的三范式》
为什么要在数据库设计时使用三范式? 答:在设计数据库中为了更好的解决 数据冗余 、数据有效性、提高存储效率考虑。 什么是数据冗余? 答:数据冗余指一个数据在一个或者多个数据文件中重复存储。这里就要设计到“键”的概念。 一、键的概念 超键 :能够决
为什么要在数据库设计时使用三范式?
答:在设计数据库中为了更好的解决数据冗余、数据有效性、提高存储效率考虑。
什么是数据冗余?
答:数据冗余指一个数据在一个或者多个数据文件中重复存储。这里就要设计到“键”的概念。
一、键的概念
超键:能够决定一条记录的单个属性或属性集合。
候选键:不含多余属性的超键。
主键:选择其中一个候选键。
假设:在师范学院,学号、课程号没有重复的情况下下,考虑以下属性
学号
姓名
课程号
成绩
课程名称
10070541001
张三
001
98
张飞
10070541002
李四
001
98
张飞
10070541002
李四
002
96
赵刚
判断是超键吗?
(学号)不能够决定一条记录,不是超键
(学号、成绩)不能够决定一条记录,不是超键
(学号、课程号)能够决定一条记录,是超键
(学号、课程号、成绩)能够决定一条记录,是超键
——从这里看出,超键的组合是唯一决定一条记录的,但是可能不是最小唯一的。
判断是候选键吗?
(课程号、课程名称)唯一,但“课程名称”为多余的属性(即由课程号可以推出课程名称,或者说如果不使用课程名称也能唯一的表示一条数据实体),因此不是候选键。
(学号、课程号)唯一,没有多余的属性所以为候选键
——从这里看出,候选键是最小的超键,也就是说没有多余属性的超键。
二、函数依赖
(一)为什么会出现出现数据冗余?
答:因为数据依赖。数据依赖的典型例子就是:函数依赖。
(二)什么是函数依赖?
答:(专业术语)若对于R(U)的任意两个可能的关系r1、r2,若r1[x]=r2[x],则r1[y]=r2[y],或者若r1[x]不等于r2[x],则r1[y]不等于r2[y],称X决定Y,或者Y依赖X。(通俗的讲)在一个关系模式中,一个属性或者属性集合x决定另一个属性y。则:y依赖x。否则不决定,就不依赖。
(三)函数依赖分类:
1、 平凡依赖与非平凡依赖:
2、 部分依赖与完全依赖:
3、 传递依赖与函数依赖:
三、数据库三范式:
第一范式1NF:原子性
定义:是指数据库表的每一列都是不可分割的基本数据项,同一列中不能有多个值,即实体中的某个属性不能有多个值或者不能有重复的属性。
第二范式2NF:消除部分依赖
定义:第二范式(2NF)是在第一范式(1NF)的基础上建立起来的,即满足第二范式(2NF)必须先满足第一范式(1NF)。第二范式(2NF)要求数据库表中的每个实例或行必须可以被唯一地区分。为实现区分通常需要为表加上一个列,以存储各个实例的唯一标识。
第三范式3NF:消除传递依赖
定义:满足第三范式(3NF)必须先满足第二范式(2NF)。简而言之,第三范式(3NF)要求一个数据库表中不包含已在其它表中已包含的非主关键字信息。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Factors of rising virtual currency prices include: 1. Increased market demand, 2. Decreased supply, 3. Stimulated positive news, 4. Optimistic market sentiment, 5. Macroeconomic environment; Decline factors include: 1. Decreased market demand, 2. Increased supply, 3. Strike of negative news, 4. Pessimistic market sentiment, 5. Macroeconomic environment.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

The main differences between Laravel and Yii are design concepts, functional characteristics and usage scenarios. 1.Laravel focuses on the simplicity and pleasure of development, and provides rich functions such as EloquentORM and Artisan tools, suitable for rapid development and beginners. 2.Yii emphasizes performance and efficiency, is suitable for high-load applications, and provides efficient ActiveRecord and cache systems, but has a steep learning curve.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

MongoDB's future is full of possibilities: 1. The development of cloud-native databases, 2. The fields of artificial intelligence and big data are focused, 3. The improvement of security and compliance. MongoDB continues to advance and make breakthroughs in technological innovation, market position and future development direction.

C is suitable for processing sensor data due to its high performance and low-level control capabilities. Specific steps include: 1. Data collection: Obtain data through the hardware interface. 2. Data analysis: convert the original data into available information. 3. Data processing: filtering and smoothing processing. 4. Data storage: Save data to a file or database. 5. Real-time processing: Ensure the efficient and low latency of the code.

Concordium: A public first-level blockchain platform that takes into account privacy and compliance is a public first-level blockchain platform. Its core lies in the clever integration of identity verification with privacy and regulatory compliance. Founded in 2018 by Lars Seier Christensen, the platform’s core technology embeds cryptographic identities at the protocol level of each transaction. This unique design ensures responsibility traceability while protecting user privacy, effectively solving the problem of conflicts between anonymity and regulatory requirements in the blockchain field. To alleviate this problem, Concordium utilizes Zero Knowledge Proof (ZKP) technology, allowing users to verify specific identity attributes without the need to disclose unnecessary personal information. This means that, despite every
