Database system principles (2) Introduction to relational models and relational operations


Relational model: a collection of conceptual apartments describing data, data connections, data semantics, and consistency constraints.

Several words in the table

  1. Attribute
    corresponds to the column in the table

  2. Domain
    The value range of the column (a collection of values ​​of the same data type)

  3. Tuples
    The rows in the table are tuples

  4. Relations
    A two-dimensional table consisting of a subset of the Cartesian product of n domains (that is, extracting from each domain as a component of a tuple) is called a relation. Since not all tuples are meaningful, only the set of meaningful tuples are relations. To put it plainly, it refers to the database table.

    The relationship has 3 attributes: (1) Relationship name (table name) (2) Attribute list and range (column) (3) Data dependency between attributes (integrity constraint)

  5. Candidate code
    can uniquely determine the attribute or attribute group of the tuple

  6. Primary key
    Select one of the candidate codes as the primary key, also called the primary key

  7. Foreign key
    There are two attributes c1 and c2 in relation A which are not candidate codes, and correspond to the primary keys c11 and c22 in another relation B. Then c1.c2 is said to be the foreign key of relations a and b.

  8. Relational Algebra
    Traditional operation form (union, intersection, difference) + specialized operation form (selection, projection, connection)

code

  1. Hypercode
    A collection of one or more attributes, which allows us to uniquely identify a tuple in a relationship.
  2. Candidate code
    is an attribute group of relational species whose value can uniquely represent a tuple. If any attribute is removed from the attribute group, it does not have this property, and such an attribute group is called a candidate code. And the attribute in any candidate code is called the main attribute.
  3. Master Code
    When designing a database, select one from multiple candidate code types in a relationship as the master code. For example, you can select ID as the master code of the instructor.

  4. An attribute group in the outer code relationship R is not the code of R, but it corresponds to the code of another relationship S, so this attribute is called the outer code of R. R is the reference relationship, and S is the referenced relationship. R refers to relationship F through foreign code F

When I searched for related information, I found a good article: relationship, relationship model, relationship model blablabla...It
contains professional terms of the database, I love it ♥.

Pattern diagram

The database schema that contains the main code and the external code dependency can be represented by a schema diagram:
Relationship : Rectangle
Relation Name : Listed above the rectangle
Attributes : Listed inside the rectangle
Master Code attribute : Underlined
External code dependency : External code attribute of the reference relationship The arrow between the main code attributes of the referenced relationship indicates.

Relational operations

  • Select special tuples (rows) that satisfy some specific predicates from a single relationship
    Insert picture description here
  • Select specific attributes from a relationship
    Insert picture description here
  • Cartesian product: Combine pairs of tuples from two relations into a single tuple
    Insert picture description here
  • r and s: Combine the same data in the two relationships into one and put them in the new relationship.
    Insert picture description here
  • r minus s: remove the same in the two relationships to form a new relationship.
    Insert picture description here
  • r Cross s: Bring the same data in two relations to form a new relation.
    Insert picture description here
  • Natural connection: The tuples matched by the natural connection operation on two relations have the same value in all the attributes shared by the two relations .
  • The five lines in the figure correspond to the five tuples (rows) after natural connection
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq1350975694/article/details/106910324