Relational model
Relational model: a collection of conceptual apartments describing data, data connections, data semantics, and consistency constraints.
Several words in the table
-
Attribute
corresponds to the column in the table -
Domain
The value range of the column (a collection of values of the same data type) -
Tuples
The rows in the table are tuples -
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)
-
Candidate code
can uniquely determine the attribute or attribute group of the tuple -
Primary key
Select one of the candidate codes as the primary key, also called the primary key -
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. -
Relational Algebra
Traditional operation form (union, intersection, difference) + specialized operation form (selection, projection, connection)
code
- Hypercode
A collection of one or more attributes, which allows us to uniquely identify a tuple in a relationship. - 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. - 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.
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
- Select specific attributes from a relationship
- Cartesian product: Combine pairs of tuples from two relations into a single tuple
- r and s: Combine the same data in the two relationships into one and put them in the new relationship.
- r minus s: remove the same in the two relationships to form a new relationship.
- r Cross s: Bring the same data in two relations to form a new relation.
- 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