Relation (database)

from Wikipedia, the free encyclopedia

The mathematical definition is the formal basis of the relation in the sense of a database relation . The relation is the basis of relational algebra , which was developed by Edgar F. Codd . A relation consists of attributes and tuples. An attribute describes the type of a possible attribute value and designates it with an attribute name. A tuple represents a concrete combination of attribute values ​​and is also referred to as a data record in the database area.

Relations as tables

In connection with relational databases , it is common to describe a relation using a table . In table form, the attributes correspond to the column headers, the attribute values ​​correspond to the entries in the columns. A tuple corresponds to a row in a table. Attribute values ​​are often wrongly referred to as an attribute.

Both the connection of attributes or attribute values ​​within a table and a link between tables using foreign keys represent a relationship. The spread of the terminology of ER models probably leads to errors . There the terms entities and relationships are used. The mistake is to distinguish between entities and relationships in principle. In principle, however, both entities and relationships are to be viewed as relations. When two relations are merged, a relationship between two tables ultimately only represents an increase in the number of elements. If a relationship is viewed as a relationship, its elements are represented as the union of the elements of the two linked relationships.

While ER models can be helpful in developing a database schema , the relational data model with its relational algebra is better suited for the basic structuring of data.

If there were a separate row in the database table for every possible combination of attribute values, then this table would represent the Cartesian product of the value sets for the columns. A database table normally only contains a very small subset of the possible tuples, so it represents a subset of this Cartesian product.

A consequence of interpreting the assignment of a database table as a set is that the individual lines are to be viewed as elements of this set. They can either be included in the set (table) or not - the number and position of an element, on the other hand, is not meaningful. With the usual database query language SQL , it is generally possible to insert an element (i.e. a row with a certain value assignment) multiple times in a table, but such a procedure is pointless: Several rows that are assigned the same values ​​have the same identity and are logically indistinguishable from each other.

definition

Many terms are used in connection with relations, but they often mean the same thing. In addition, there are both German and English names that are further mixed up. The following table lists frequently used terms.

relational model informal term Explanation
German English German English
Relation, entity type, entity class relation table table A table in a database
Tuple, entity tuple , entity row row A horizontal record of a table in the database
relationship relationship Relationship between individual tuples
Cardinality cardinality Quantity specification for the relationship of individual tuples (e.g. 1: 1, 1: n, n: m)
attribute attribute column column vertical column index of a table
Degree degree Number of uniquely identifying attributes
Primary key primary key unique identifier
Foreign key foreign key Keys from another table in order to be able to establish a relationship
Range of values domain Type type Values ​​that an attribute can assume
Scalar scalar value value Value of an attribute in a tuple

See also

Individual evidence

  1. ^ Date, CJ ( 2003 ). Introduction to Database Systems . 8th edition, Addison-Wesley. ISBN 0-321-19784-4 .