Home Database Mysql Tutorial 【数据库系列】之《设计的三范式》

【数据库系列】之《设计的三范式》

Jun 07, 2016 pm 03:24 PM
Why use database series Timing

为什么要在数据库设计时使用三范式? 答:在设计数据库中为了更好的解决 数据冗余 、数据有效性、提高存储效率考虑。 什么是数据冗余? 答:数据冗余指一个数据在一个或者多个数据文件中重复存储。这里就要设计到“键”的概念。 一、键的概念 超键 :能够决


为什么要在数据库设计时使用三范式?

答:在设计数据库中为了更好的解决数据冗余、数据有效性、提高存储效率考虑。

什么是数据冗余?

答:数据冗余指一个数据在一个或者多个数据文件中重复存储。这里就要设计到“键”的概念。

一、键的概念

超键:能够决定一条记录的单个属性或属性集合。

候选键不含多余属性的超键。

主键:选择其中一个候选键。

假设:在师范学院,学号、课程号没有重复的情况下下,考虑以下属性

      学号

   姓名   

  课程号  

  成绩  

  课程名称  

   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)要求一个数据库表中不包含已在其它表中已包含的非主关键字信息。

【数据库系列】之《设计的三范式》



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

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.

Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Apr 21, 2025 am 08:57 AM

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: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

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.

What is the difference between php framework laravel and yii What is the difference between php framework laravel and yii Apr 30, 2025 pm 02:24 PM

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.

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

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: The State of the Database MongoDB's Future: The State of the Database Apr 25, 2025 am 12:21 AM

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.

How to process sensor data in C? How to process sensor data in C? Apr 28, 2025 pm 10:00 PM

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.

Why should you listen Why should you listen Apr 21, 2025 pm 09:00 PM

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

See all articles