Relational model in database

Three elements of the relational model

1 Basic structure: Relation/Table

2 Basic operations: Relation Operator (various calculation operations)

3 Integrity constraints: to achieve integrity, referential integrity and user-defined integrity

Candidate code/candidate key
An attribute group in the relationship, its value can uniquely identify a tuple, if any attribute is removed from the attribute group, it does not have this property, such attribute group is called candidate code

For example: "student (S#,Sname,Sage,Sclass)", S# is a candidate code. In this relationship, the S# of any two tuples must be different, and the Sname of these two tuples, Sage and Sclass may be the same, and all S# are candidate codes.

Sometimes there are many sets of candidate codes in the relationship

The attribute S# is the candidate code, and the attribute group (Sname, Saddress) is also the candidate code (two students with the same name and the same address do not exist)

Master code/primary key
When there are multiple candidate codes, one can be selected as the master code

When the DBMS uses the master code as the main clue to manage the tuples in the relationship

Primary attributes and non-primary attributes The attributes
contained in any candidate code are called primary attributes, and the other attributes are called non-primary attributes.

The simplest, candidate code contains only one attribute

At the most extreme, all attributes constitute the candidate code of this relationship, called the full code

Foreign code/foreign key
An attribute group in a relation R is not a candidate code for R, but it corresponds to a candidate code for another relation S. This attribute group is called the foreign code or foreign key of R.

For example: the customer number in the "contract" relationship is not a candidate code, but it is indeed a foreign code. Because it corresponds to the candidate code "customer number" in the "customer" relationship.

Two relationships are usually connected by external codes.

Guess you like

Origin blog.csdn.net/aqiuisme/article/details/108891176