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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months 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)

Failed to obtain Taobao order data: Why do you still jump to the login page with cookies and URL parameters? Failed to obtain Taobao order data: Why do you still jump to the login page with cookies and URL parameters? Apr 02, 2025 am 06:54 AM

Difficulty in obtaining Taobao order data: Bypassing the challenge of login page Many friends will encounter a difficult problem when trying to obtain information about purchased products on Taobao:...

Jiutian Computing Power Platform Task: Will the computing task continue to run after the local computer is shut down? Jiutian Computing Power Platform Task: Will the computing task continue to run after the local computer is shut down? Apr 01, 2025 pm 11:57 PM

Discussion on the task status after the local computer of Jiutian Computing Power Platform is closed. Many users will encounter a question when using Jiutian Computing Power Platform for artificial intelligence training...

Is the conversion speed fast when converting XML to PDF on mobile phone? Is the conversion speed fast when converting XML to PDF on mobile phone? Apr 02, 2025 pm 10:09 PM

The speed of mobile XML to PDF depends on the following factors: the complexity of XML structure. Mobile hardware configuration conversion method (library, algorithm) code quality optimization methods (select efficient libraries, optimize algorithms, cache data, and utilize multi-threading). Overall, there is no absolute answer and it needs to be optimized according to the specific situation.

In Go, why does printing strings with Println and string() functions have different effects? In Go, why does printing strings with Println and string() functions have different effects? Apr 02, 2025 pm 02:03 PM

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

Why is it necessary to pass pointers when using Go and viper libraries? Why is it necessary to pass pointers when using Go and viper libraries? Apr 02, 2025 pm 04:00 PM

Go pointer syntax and addressing problems in the use of viper library When programming in Go language, it is crucial to understand the syntax and usage of pointers, especially in...

Why do all values ​​become the last element when using for range in Go language to traverse slices and store maps? Why do all values ​​become the last element when using for range in Go language to traverse slices and store maps? Apr 02, 2025 pm 04:09 PM

Why does map iteration in Go cause all values ​​to become the last element? In Go language, when faced with some interview questions, you often encounter maps...

Go language slice: Why does it not report an error when single-element slice index 1 intercept? Go language slice: Why does it not report an error when single-element slice index 1 intercept? Apr 02, 2025 pm 02:24 PM

Go language slice index: Why does a single-element slice intercept from index 1 without an error? In Go language, slices are a flexible data structure that can refer to the bottom...

Does XML modification require programming? Does XML modification require programming? Apr 02, 2025 pm 06:51 PM

Modifying XML content requires programming, because it requires accurate finding of the target nodes to add, delete, modify and check. The programming language has corresponding libraries to process XML and provides APIs to perform safe, efficient and controllable operations like operating databases.

See all articles