search
HomeDatabaseMysql Tutorial戏谈数据库三范式

数据库三范式想必大家并不陌生,官方的解释很抽象,初学者比较难理解。对于这块知识,我是看了会,会了忘,忘了再看。每当别人问我的时候,必须先看看教材,回顾一段时间才能理清。 为什么当别人提问时不能立马把三范式的经典思想说出来呢?通过听米老师的“

数据库三范式想必大家并不陌生,官方的解释很抽象,初学者比较难理解。对于这块知识,我是看了会,会了忘,忘了再看。每当别人问我的时候,必须先看看教材,回顾一段时间才能理清。

为什么当别人提问时不能立马把三范式的经典思想说出来呢?通过听米老师的“如何高效学习”这堂课,我发现原因是我自己没有融入到三范式中,三范式没有和自己发生关系。下面,我用三个有趣的小故事帮助大家快速、深刻的理解三范式的含义。

第一范式,官方解释:关系模式R的每个关系r的属性值都是不可分的原子值。这个官方解释还不算太难,比如我们想把“电话号码”作为数据库字段,在“电话号码”下面又分“手机号码”和“座机号码”,这就违反了第一范式,用我的话说就是“把事说清了”。你只说“电话号码”,我知道你说的是“手机号码”还是“座机号码”?

第二范式,官方解释:非主属性必须完全函数依赖于R的主关系键。怎么样,有点晕了吧!比如:在SCD表中,有字段SNO,SN,Age,Dept,MN,CNo,Score。知道SNo可以确定SN、Age、Dept、MN,知道SNo、CNo可以确定Score。这个事好比土匪们选大哥,小弟SN、Age、Dept、MN选举SNo当土匪头子,Score选举SNo、CNo两个人共同当土匪头子。结果意见达不成一致,土匪们闹分裂,一句话“只要有一个人不同意,这事就不能通过”。大哥SNo带着小弟SN、Age、Dept、MN成立土匪旗号SD,大哥SNo又和CNo带着小弟Score合伙成立土匪旗号SC,到此,故事告一段落。

第三范式,官方解释:每个非主属性都不传递函数依赖于R的主关系键。这个怎么样,彻底晕了吧!比如:在SD表中,知道SNo可以确定Dept,知道Dept可以确定MN(系主任名)。这事咱接着上面第二范式的土匪故事接着讲,大哥SNo有小弟SN、Age、Dept、MN,但Dept特别有才,又把MN招为自己的小弟,天天忽悠MN,给MN灌输反动思想,终于有一天Dept带着MN独立了,成立了土匪旗号D。大哥SNo感觉SD已经不完整了,把土匪旗号改为S。SNo经过这次教训,决定下道命令:“一个人只能扮演一个角色”,否则就是不符合三范式,造成关系模式分解。

到此故事讲完了,想必通过这个小故事,大家肯定把三范式的精髓深深的刻在了脑中。

Statement
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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

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

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools