Chapter 2 Relational Database

2.1 Overview of the relationship model (omitted)

2.2 Relationship operations

2.2.1_ Basic relational operations

Commonly used relational operations in relational models include two parts-Query operationwithUpdate operation(Insert, delete, modify)
among them, the query operation5 basic operationsYesselectprojectionanddifferenceCartesian Product

2.2.2_ Classification of relational database languages

Early relationship manipulation capabilities are usually usedAlgebraic wayorLogical wayTo represent, respectively calledRelational algebrawithRelational calculus(No need to understand the calculation), andsql languageIt is a structured query language between the former two.
Insert picture description here

2.3 Integrity of the relationship

2.3.1_ Three types of integrity constraints of relations

There are three types of integrity constraints in the relational model:Physical integrityReferential integritywithUser-defined integrity;
Entity integrity and referential integrity are the integrity constraints that the relationship model must meet, called the relationshipTwo invariances

2.3.2_ Entity integrity

Explanation of entity integrity rules:
(1) Entity integrity rules are for basic relationships. A basic table usually corresponds to a set of entities in the real world.
(2) Entities in the real world are distinguishable, that is, they have a certain unique identification.
(3) The main code is used as the unique identifier in the relational model.
(4) The attribute in the main code, that is, the main attribute, cannot take a null value . The primary attribute takes a null value, which means that there is an unidentifiable entity, that is, there is an indistinguishable entity. This contradicts point (2), so this rule is called entity integrity

2.3.3_ Referential integrity

Referential integrity rule :
If the attribute (or attribute group) F is the outer code of the basic relation R, it corresponds to the main code Ks of the basic relation S (the basic relation R and S are not necessarily different relations), then for each The value of a tuple on F must be:
1. Or take a null value (each attribute value of F is a null value)
2. Or equal to the main code value of a tuple in S

2.3.4_ User-defined completeness

Example: Course (course number, course name, credits)
"Credits" attribute can only take the value {1, 2, 3, 4}

2.4 Relational algebra

2.4.1_ Traditional set operations

Insert picture description here

2.4.2_ Specialized relational operations

Insert picture description here
Insert picture description here
1. Select
Insert picture description here
2. Project
Insert picture description here
3. Connect

Equivalent connection: connect tuples with the same attribute value.
Natural connection: natural connection is a special kind of equivalent connection . The components to be compared in the two relations must be the same attribute group. Remove the duplicate attribute column in the result. (Different from the equivalent connection)
General connection: Omitted

Insert picture description here
Insert picture description here

  1. except
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43907296/article/details/110751119