Calculating candidate code integrity, the master key and the foreign key relationship, the relational algebra, Relationship - principles and applications of the database (6)

A candidate code, the primary code and an outer code

1. The candidate code (Candidate Key)

Definition: can uniquely identify a relationship attribute or set of attributes tuples, referred to as candidate codes.

Properties: having unique properties and minimal resistance .

2. The relationship between the primary key and the foreign key

Master Code
  • Definition: selecting from a plurality of candidate codes as a query, insert, delete tuple manipulated variable, the selected candidate code is called code master relation (primary key, the master key, the key relationship, keywords)
  • Each relationship must have one and only one master code, can not be repeated after the selection.
The main attribute relationship
  • Main properties (Prime the Attribute) : each attribute contained in the main code is called the primary attribute.
  • Non-primary property (Non-Prime the Attribute) : attribute is not included in any candidate code is referred to as non-primary attributes (attributes or code).
  • Full code: candidate code combination of all the attributes of the relationship.
  • Ultra Code : candidate code comprising a combination of properties.
Outer code
  • Definition: If a relation R & lt 2 a set of attributes or X is not R & lt 2 of the main code, but another relationship R & lt . 1 of the main code, the attribute or attribute called relationship X group R & lt 2 outside the outer code of keys (Foreign Key), and said R & lt 2 as a reference relationship (Referencing relation), the relationship between R & lt . 1 referred to by reference to the relationship (referenced relation).
  • Referring to the relationship between the outer code and the master key must be defined with reference to the relationship on the same domain.

Integrity Second, the relationship between

1 Overview

In order to maintain the consistency of data in a relational database with the real world, the insertion of a relational database, delete and modify operations must have certain constraints, these constraints is actually the real demands of the world. Any relationship at any time should meet these semantic constraints.

2. The three types of integrity constraints

Entity integrity must satisfy nature
  • Definition: entity integrity refers to the value of the primary key can not be empty or partially empty.
Referential integrity properties must be met
  • If the relation R: define two outer code and the relation R X 1 each value of the primary key matches, then X is

    Or equal to R & lt . 1 a certain value of the primary key or null value.

User-defined semantic integrity constraints specific areas
  • Definition: For the constraints of a particular relational database, which reflects the semantic data requirements must be met for a specific application design.

Third, the relational algebra

1. Classification of relational algebra operators

  • Relational algebra is an abstract query language
  • Operand with the result of the operation of relational algebra are relations
  • Relational algebra operators
Relational algebra operations by different operators can be divided into two categories
  • The traditional set operations : the relations as a set of tuples, tuples as elements in the set operation is performed, the calculation is performed from the perspective of "horizontal" orientation, i.e., the relationship between the rows. Including and (∪), the difference (-), cross (∩) and generalized Cartesian product (×) and the like operation.

    • Traditional set (except Cartesian product) is a typical binary operator. Hence the need for the two relationships, the relationship between two R, S, if yes

      • Having the same degree
      • R i-th attribute and S i th attribute must be from the same domain (column homogenous)

      It said that relations R, S is compatible.

    • And Operation: add a record;

      Dropout Operation: delete a record.

  • Special relationship operations : not only line operation also involves column operation, such operations for database applications and the introduction of special operations. Including selecting (OK), the projection (ranks are changed), the connection (two items: θ connection equivalent / above / below, remove duplicate natural join columns) and divide the like operation.

    • θ connection : equi connection is less than, greater than a connecting
      NATURAL connection : In the case of equivalent connection, when the connection attributes X and Y have the same attribute group, the repetition of the columns in the result of the attribute is removed

    • Equijoins differs connected NATURAL
      NATURAL connection requires the same attribute name attribute value equal to, but does not require the equivalent connection;
      NATURAL connection is repeated to remove equijoins column.

    • Division is a binary operator, with relation R (X, Y) and the relationship between S (Y, the Z), wherein X, Y, Z for the attribute set, R and S in the Y-Y can have different attribute names , but the corresponding attribute must be from the same domain.

      Taking into account the rows and columns for the query contains the "All" and "at least" and the like.

Fourth, the tuple calculus of relations

  • Definitions : tuple relational calculus in order tuple as a unit , by the predicate equation constraint tuples to find conditions, can be expressed as {T | [Psi] (T)} .

    Wherein, t is a tuple variable, i.e. the query object. Formula predicate calculus ψ called tuples, i.e., the condition of the query.

  • {T | ψ (t)} represents that the set of tuples t is true.

    ψ (t) by atomic formula, bound variables, configuration variables and operators freedom.

  • If there is a tuple variable before tuple calculus formula universal quantifier and existential quantifier , called the variable is constrained tuple variable, otherwise known as free tuple variables.

Fifth, the domain relational calculus

Is defined : A tuple field as a unit, according to the constraint condition equation predicate query tuples needed, expressed as

​ {<x1,x2,…xn>|R(x1,x2,…xn)}

  • Wherein X . 1 , X 2 , ... X n- represents the domain variables, i.e., components of the tuple, R represents a formula made up of atoms;
  • R is defined as a tuple relationship calculus, it is also repeated by the atomic formula, free variables, variables and operators constraints constituted.
Domain relational calculus Language
QBE(Query By Example)
  • A highly non-procedural, screen form-based query language.
  • User by filling out the form, and gives examples of the way to get the query results.
  • Query examples given are domain variables.
Use QBE language
Relation name Attribute 1 …… Properties n
Operation Command Property values ​​or query …… Property values ​​or query
  • Operation Command: P to print or display, U modification, I insert, D deleted
  • Or write the relationship in two rows
  • Multi-table queries, need to give the same example of the variable domain
Published 77 original articles · won praise 30 · views 6377

Guess you like

Origin blog.csdn.net/weixin_45926367/article/details/104934143