Database and keys

Database is a set of information organized and adapted for processing by a computer system.

Database management system (DBMS) is a set of general or special purpose tools that provide creation, access to materials and database management.

The main functions of the DBMS:

  • data management
  • data change logging
  • data backup and recovery
  • support for data definition and manipulation language

Relational data model

Relational data model is logical data model and applied theory of building relational databases.

The relational data model includes the following components:

  • Structural aspect - data is a set of relationships.
  • Integrity aspect - relationships meet certain integrity conditions: domain (data type) level, relationship level, and database level.
  • Aspect of processing (manipulation) - support for operators to manipulate relations (relational algebra, relational calculus).
  • Normal form is a property of relation in relational data model that characterizes it in terms of redundancy and is defined as a set of requirements that a relation must satisfy.

Simple, composite, candidate and alternate key

Simple key consists of one attribute (field). Composite - of two or more.

Candidate key - simple or composite key that uniquely identifies each record in a dataset. In this case, the candidate key must have the criterion of non-redundancy: when you delete any of the fields, the set of fields ceases to uniquely identify the record.

From the set of all candidate keys of the dataset, the primary key is selected, all other keys are called alternate.

Primary key

Primary key in the relational data model is one of the candidate keys of the relationship, selected as the primary key (the default key).

If a relationship has a single candidate key, that is also the primary key. If there are several candidate keys, one of them is chosen as the primary one, and the others are called “alternate”.

The most convenient candidate key is usually chosen as the primary one. Therefore, as the primary key, as a rule, the one that has the smallest size (of physical storage) and/or includes the smallest number of attributes is chosen. Another criterion for choosing a primary key is maintaining its uniqueness over time. Therefore, they try to choose such a candidate key as the primary key, which is most likely to never lose its uniqueness.

Foreign key

Foreign key is a subset of the attributes of some relation A, the values of which must coincide with the values of some candidate key of some relation B.


Read also:


Comments

Popular posts from this blog

Methods for reading XML in Java

XML, well-formed XML and valid XML

ArrayList and LinkedList in Java, memory usage and speed