当前位置:网站首页>Paradigm in database: first paradigm, second paradigm, third paradigm

Paradigm in database: first paradigm, second paradigm, third paradigm

2022-07-05 10:53:00 It was delicious when I was young

Tuples : A line in the table

code : A column in the table

Candidate code : can Unique identification , Such as through ( Id card number ) perhaps ( School , class , Student number ) Can uniquely identify a person ; Main attribute : Attributes that have appeared in the candidate code

Main code : Also called primary key , Choose a boss from the candidate code

Foreign code is also called foreign key . If An attribute in a relationship yes The main code in another relationship Then this attribute is foreign code

First normal form , Second normal form , Super simple introduction of the third paradigm

First normal form : Can not be further divided

For example, there are two attributes in a table : company 、 goods ( name 、 Number ), However, the commodity can be identified by its name 、 Quantity means , Do not conform to the , and company 、 name 、 Number accord with

Second normal form : Based on the first paradigm , Eliminate partial dependence

The order number Product number Product quantity Product discounts product price Order amount The order time
10001251000.9950002022-07-22
10001262000.8970002022-07-23

book single Number 、 production product Number → production product Count The amount 、 production product fold buckle 、 production product price grid book single Number → book single gold forehead 、 book single when between The order number 、 Product number \to Product quantity 、 Product discounts 、 product price \\ The order number \to Order amount 、 The order time book single Number production product Number production product Count The amount production product fold buckle production product price grid book single Number book single gold forehead book single when between

‘ The order number ’ and ‘ Product number ’ Is the primary key of the table ( Main code ), These two fields together determine ‘ Product quantity ‘ ’ Product discounts ‘ ’ product price ‘ ,

and ‘ Order amount ’ and ‘ The order time ’ Only by ‘ The order number ’ decision , Not by Primary key (‘ The order number ’ and ‘ Product number ’) Joint decision , therefore ‘ Order amount ’ and ‘ The order time ’ yes Depends in part on the primary key

Correct version

The order number Product number Product quantity Product discounts product price
10001251000.99
10001262000.89
The order number Order amount The order time
1000150002022-07-22
1000170002022-07-23

Third normal form : Based on the second paradigm , Eliminate delivery dependency

ID number full name Gender Age
34666666666 Zhang San male 22

body Share Prove → surname name → sex other 、 year age Id card \to full name \to Gender 、 Age body Share Prove surname name sex other year age

“ Gender ” and “ Age ” Although indirect dependence ‘ ID number ’, but Directly dependent on Yes. “ full name ”, Correct version

ID number full name
34666666666 Zhang San
full name Gender Age
Zhang San male 22

The transfer function depends on body Share Prove → surname name → sex other 、 year age        but yes        sex other 、 year age ↛ surname name ↛ body Share Prove Id card \to full name \to Gender 、 Age ~~~~~~ however ~~~~~~ Gender 、 Age \not\to full name \not\to Id card body Share Prove surname name sex other year age        but yes        sex other year age surname name body Share Prove

原网站

版权声明
本文为[It was delicious when I was young]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051017144085.html