当前位置:网站首页>Chapter II relational database
Chapter II relational database
2022-06-11 17:22:00 【Lanterns can only come to the classroom to experience life】
List of articles
2.1 Relationship
Relation is a data structure of relation model .
The logical structure is reflected in a table :
- Each column of the relationship is called
attribute, For example, in the tableuser_idIs the user identification number , Attribute can describe the meaning of the value of this column . - Relationships are sometimes called
surface.
Basic concepts
Domain
Write it down as D(domain)
The cartesian product
Cartesian product is an operation on a field , Write it down as :
D 1 × D 2 × . . . × D n = { ( d 1 , d 2 , . . . , d n ) ∣ d i ∈ D i , i = 1 , 2 , . . . , n } D_1×D_2×...×D_n = \{(d_1, d_2, ...,d_n)|d_i∈D_i, i=1,2,...,n\} D1×D2×...×Dn={ (d1,d2,...,dn)∣di∈Di,i=1,2,...,n}
There are currently three domains ( Teachers' 、 Course 、 Student )
Use one that may not be accurate , But an easy way to describe Cartesian product : Cartesian product is a combination of elements in different fields
For example, here is 【 Li Yi 】 and 【 mathematics 、 English 】、【 Student 】 The combination of .
Cartesian product has no semantics , It's like you can't make sure 【 Li Yi 】 teach 3 Subjects , The student of the subject happens to be that 3 A student .
Every combination in Cartesian product ( Every line ) Is called a
n Tuples, It depends on how many columns there are in each row ( In the above example is 3 Tuples ), Write it down as :
( d 1 , d 2 , . . . , d n ) (d_1, d_2,...,d_n) (d1,d2,...,dn)A value in a tuple is called
component([ Li Yi | English | Wang Chieh ] Chinese and English are one component ).The different values allowed in a domain are called the values of this domain
base( The base number of teachers =2, The cardinality of the subject =2, The cardinality of the student field =3).
Cardinality in Cartesian product = The product of the cardinality of each field
Relationship
RelationshipIs a subset of the Cartesian product , Expressed as :
R ( D 1 , D 2 , . . . , D n ) R(D_1, D_2, ..., D_n) R(D1,D2,...,Dn)
R Express Relation;n It's a relationshipObjectiveordegree, Is how many attributes a relationship has .
Special ,n=1 It's calledUnit relationship,n=2 It's calledBinary relationship.Candidate code: A set of attributes can determine a unique tuple .
① This group can't do without one attribute
② You can have only one attribute- If a relationship has multiple candidates , Then select one of them as
Main code.
For example, in the student information table , There are two candidate codes :
1.{ Student number }
2.{ ID number }
At this point, if you select{ Student number }As the unique identification of students , that{ Student number }It is called the main code ( choice{ ID number }Of course, it can be ). Main attribute: Attributes in candidate code .Non primary property: Attributes that do not belong to the candidate code .- In extreme cases , All attributes in a relationship are candidates for that relationship , Then call this candidate code
Full size.
Three types of relational tables
- Basic table ( Also known as
Basic relationshiporBase watch)
The actual table :
- Query table
The table obtained according to the query results .
Query age is greater than 20 Year old user :
- View table
It's a virtual table , Does not exist in disk space .
It is actually a collection of query statements , Is encapsulated , Like a function .
There will beCheck age 20 Users older thanThis requirement , The package becomes aView.
So the view table :
The nature of the basic relationship
Every component of the basic relationship , Must be inseparable .
That is, every data item must be a basic data type ( integer 、 character string 、…), It cannot be a table .
2.1.2 Relationship model
The relational pattern is represented in Chapter 2 as R(U, D, DOM)
U: The set of attribute names that make up the relationship
D:U The domain from which the attribute in the
DOM: Property to a collection of domain images
Roast about the textbook , this DOM Is the description of a person's words ?
for instance , A relationship is as follows :
that :
U:{ Faculty number 、 Student number 、 Course no. }
D:{ Teachers' 、 Student 、 Course }
DOM:{DOM( Faculty number ) = Teachers' 、DOM( Student number )= Student 、DOM( Course no. )= Course }
Mapping is like a function , Give it an input , Get an output .
DOM It's input.attributeGet theDomain.
2.2 Relationship operation
Additions and deletions , Understand everything .
Insert 、 Delete 、 modify 、 Inquire about .
- Query operations include :
choice、Projection、Connect、except、and、Bad、hand over、The cartesian productetc. . - The objects and results of the operation are collections .
2.3 The integrity of the relationship
Entity integrity:
If the property ( Group )A It's the relationship R The main attribute of , that A Not empty .
In fact, the primary attribute is to distinguish a tuple in the relationship ( A line ) Of Conditions , If the condition is empty , That is, unconditional , Then it is impossible to distinguish any tuple in the relationship .
Referential integrity:
Student ( Student number , full name , major )
Course ( Course no. , Course name , credits )
Elective ( Course no. , Student number , Class hours )Student numberIs the student's main code ,Course no.Is the main code of the course ,Course no.andStudent numberIt is the main code of elective course .
Reference refers to : An attribute of a basic relationship quote The properties of other relationships .
hypothesis F It's the relationship R Properties of ( One or a group of ), but F No Relationship R The main code of ,Ks yes Relationship S The main code of . If F And Ks Corresponding ( identical ), said F yes R Of Outer code ,R by Reference relationship ,S by The referential relationship or Target relationship .
R Each tuple in F The value on the property is either empty , Or for the relationship S The main code value of a tuple on .
Student ( Major number , Student number , full name )
major ( Major number , Major name )
In student relations , The major number is either empty ( No major assigned ), Or it is a major code value in the specialty ( A major )
User defined integrity
There are many user-defined integrity , such as :
A property must be non empty
The value of a property must be in 0~100 Between ( achievement )
wait .
2.4 Relational algebra
2.4.1 Traditional set operations
hand over 、 and , Everyone knows .
Bad:
Relationship R And relationships S The difference is recorded asR-S, Is to remove R Of S Part of .
The cartesian product
Relationship R And relationship S The Cartesian product of is written as :
R × S = { t r t s ⏠ ∣ t r ∈ R ∧ t s ∈ S } R×S = \{\overgroup{t_r \ \ t_s}|tr \in R\land ts\in S \} R×S={ tr ts∣tr∈R∧ts∈S}
2.4.2 Special relational operations
1. choice
σ F ( R ) = { t ∈ R ∧ F ( t ) = t r u e } σ_F(R) = \{ t∈R∧F(t)=true \} σF(R)={ t∈R∧F(t)=true}
among F On condition that , The effect of the selection operation is : Filter out the conditions in the relationship F tuples .
Choose the conditions : Older than 20:
2. Projection
Select a column from the relationships as the new relationship .
∏ A = { t [ A ] ∣ t ∈ R } \prod_A = \{ t \quad [A] | t∈R \} A∏={ t[A]∣t∈R}
3. Connect
Connections are also known as θ Connect , It is to select the part satisfying the condition from the Cartesian product of two relations , Write it down as :
R ⋈ A θ B S = { t r t s ⏠ ∣ t r ∈ R ∧ t s ∈ S ∧ t r [ A ] θ t s [ B ] } R \underset{AθB}⋈ S = \{ \overgroup{t_r \ \ t_s} | t_r∈R ∧t_s∈S∧t_r[A]θt_s[B] \} RAθB⋈S={ tr ts∣tr∈R∧ts∈S∧tr[A]θts[B]}
θ Is the equivalent connection , From the relationship R and S Select an attribute from the list A and B Equal tuples , Spliced into the same tuple . Natural join The attributes in the connected tuple will be removed A Or attributes B( Because they are both equal ).
3.1 External connection
Equivalent connection is actually to filter out the parts with the same attributes in two relationships .
There are two tables. :
Both tables have a common attribute : Professional code , So through this property , We can find out the corresponding major of each student .
Full outer join :
Professional code It's redundant .
Left outer connection and right outer connection
Relationship R And S Do according to attribute F Equivalent connection ,R Some tuples in may not exist S in F Property has the same value .(S Some tuples in may also be in R No correspondence found in )
Then it will be discarded in the all outer connection , These discarded tuples are called Floating tuples .
According to the example, it means :
A student's major number is wrong for some reason , Cannot find in the specialty table .
A major is too popular , None of the students chose .
Remember R And S The connection is marked as :
R ⋈ A θ B S R \underset{AθB}⋈ S RAθB⋈S The left outer join Just keep it R Medium Floating tuples , Right connection Just keep it S Medium Floating tuples .
take R Write it down as a student form ,S Record it as a professional table
The left outer join ( Retain
Student listMediumFloating tuples)Right connection ( Retain
Professional watchMediumFloating tuples)
边栏推荐
- 通过Xshell连接有跳板机/堡垒机的服务器
- 拜登下令强制推行零信任架构
- Message queue push / pull mode Learning & ActiveMQ and JMS learning
- Exception handling and exception usage in golang
- Analysis report on the "fourteenth five year plan" proposal and innovation environment of global and Chinese sodium pyrophosphate industry (2022-2028)
- Characteristics of interfaces & comparison between interfaces and abstract classes
- Analyze which should be tested in PMP and ACP with actual cases? Which is more useful?
- ShellBrowser . NET Crack
- 信息安全数学基础 Chapter 3——有限域(一)
- Authing Share|理解 SAML2 协议
猜你喜欢

Development planning of China's stainless steel market and suggestions on the development direction of the 14th five year plan 2022-2028

Haas, which integrates relevant technologies of Alibaba cloud, Dharma Institute and pingtouge, has officially announced the book

Chip mass production, oppo entering a new era?

Axi protocol Basics

活动 | Authing 首次渠道合作活动圆满落幕

如何成为一个乐观派组织?

C语言:使用.h和.c文件遇到的问题总结

子类继承了什么、多态、 向上转型

From a "trendsetter" to a "wind chaser", can master Kang still lead the market?

Analysis report on sales status and supply and demand prospects of phosphoric acid fuel cell industry in the world and China 2022-2028 Edition
随机推荐
信息安全数学基础 Chapter 4——二次剩余与方根
Redis - learn five types of NoSQL
Association relationship
Connection and difference of network streaming media protocol (RTP RTCP RTMP HLS)
Authing 双周动态:Authing 论坛上线(4.25-5.8)
LeetCode——42. Connected to rainwater (double pointer)
Learning C language from scratch day 039
Song of the sea in 5g Era
How to become an optimist organization?
启牛推荐开通的股票账户安全吗?靠谱吗
Connect the server with springboard / fortress through xshell
Talk about the interview questions of the collection
Axi protocol Basics
^32 execution context stack interview questions
How to store tree structure in database
Authing biweekly news: online application market (5.10-5.22)
Jinte Net Foundation will participate in the global strategy conference of dimension chain through online live broadcast
Kernel density estimation (2D, 3D)
DFS and BFS notes (I) breadth first search based on C language
Authoring share | understanding saml2 protocol



