Database Review Chapter II

Source: Internet
Author: User

[TOC]

2.1 Relational data structures and formal definitions 1. Relationship

The data structure of a relational model has only one data structure: relationships

Formal definition of relational data structures:

1. Domains (domain)

? A set of values that have the same data type (for example, all positive integer collections of \ (1...100\) )

2. Cartesian product (Cartesian product)

An operation on a field

Defined:

Given a set of domains, \ (d_1,d_2, ...). d_n\) , whose cartesian product is :

\ (d_1 \times d_2 \times ... \times d_n = \{(d_1,d_2,..., d_n) | d_i \in d_i, i = 1,2...,n\}\)

where each element \ ((d_1,d_2,..., d_n) \) is called a \ (n\) tuple, each value \ (d_i\) is called a component

The number of different values allowed for a domain is called cardinality

If \ (d_i\) is a finite set with a base of \ (m_i\) , then the cardinality of the Cartesian product \ (m\) is:

$M = \prod_{i=0}^{n} m_i $

Cases:

\ (d_1 = \{a,b,c \}, d_2 = \{\}\)

$ d_1 \times d_2 = {(a,1), (a,2), (b,1), (b,2), (c,1), (c,2)}$

3. Relationship (relation)

Defined:

$D _1 \times d_2 \times ... the subset of \times D_n $ is called a relationship on the domain \ (d_1, d_2,..., d_n\) is represented as:

\ (R (d_1,d_2,... D_n) \) $ R $ is the name of the relationship, \ (n\) is the degree of the relationship (degree)

If the value of an attribute in a relationship uniquely identifies a tuple (which can be understood as an instance), and its subset cannot, it is called the candidate code for the attribute group.

If a relationship has multiple candidates, one of them is selected as the main code.

The attribute in the candidate code is the primary attribute, otherwise the non-primary attribute, or the non-code attribute

Cases:

? A student has the identity card number, the number, the name these three attributes, the Social security number and the school number all can uniquely identify one meta-ancestor, therefore is the candidate code, the main code in these two intermediate chooses. And the name is a non-primary attribute.

2. Relationship Mode

Can be formalized to represent:

$ R (u,d,dom,f) $

\ ( r\) is the relationship name, \ (u\) is the collection of property names that comprise the relationship, \ (d\) is the domain from which the property is from \ ( u\) , \ (dom\) is a property-to-domain image collection , \ (f\) is a collection of dependencies between attributes.

A relationship is the state or content of a relationship pattern at a certain point in time. The relationship pattern is static and stable, and the relationship is dynamic and changing with time.

3. Relational database

The type of relational database is also a relational database schema and a description of the relational database.

The value of a relational database is the set of relationships (corresponding to the description of the relational schema above) that these relational patterns correspond to at a particular time, often referred to as relational databases.

2.2 Relationship Operations 3. Integrity of the relationship 1. Entity integrity

If attribute a (one or a group) is the primary attribute of the basic relationship R, then a cannot be null (not known or meaningless)

2. Referential integrity

property values between different tables are referenced by each other, and you need to ensure that these values are not illegal.

definition: set \ (f\) is a basic relationship \ (r\) for one or a set of properties, but not \ (r\) code. \ (k_s\) is the main code of the basic relationship \ (s\) . If \ (f\) corresponds to \ (k_s\) , it is called \ ( f\) is the outer code of \ (r\) , and the basic relationship \ (r\) is the reference relationship.

In addition, the external code is not necessarily the same name as the corresponding master code

The definition above:

For each \ (r\) , the value on \ (f\) must be null or the value of the primary code of a tuple in \ (s\)

(It can be understood that a value must be meaningful.)

4. Relational Algebra 1. Set operation

(1) and

\ (r \cup S = \{T | t \in R \or T \in s\}\) The result is still a \ (n\) relationship

(2) Poor

\ (r-s = \{T | t \in R \and T \notin s\}\)

(3) Pay

\ (r \cap S = \{T | t \in R \and T \in s\}\)

\ (r \cap S = R-(r-s) \)

(4) Cartesian product

(as I've described before, I won't say it.)

2. Relational operations

(1) Select

\ (\sigma (R) = \{t|t \in F (t) = ' true ' \}\)

\ (f\) indicates a selection condition, which is a logical expression

(2) projection

The projection from \ (r\) is the selection of several attributes from \ (r\) to form a new relationship

$\pi _a (r) = {r[a]|t \in r} $

\ (a\) is a property column in \ (r\) , and the projection operation is an operation from the angle of the column

(3) connection

A tuple that satisfies a certain condition between attributes is selected from the Cartesian product of two relations.

\ (\{t_rt_s | t_r \in r \and t_s \in s \and t_r[a] \theta t_s[b] \}\)

\ (\theta\) is a comparison operator, and A and B are groups of attributes that are equal and comparable to those listed in R and S.

Join Operations Select the R relationship from the Cartesian product of R and S on the value of the A attribute group and the S relationship on the value on the B attribute group satisfies the comparison relationship $\theta $ tuple

The connection that the operation is = is an equivalent connection. A natural connection is an equivalent connection

(4) except

If T is the result of a relationship r divided by relation s, then T contains all the properties and values in R but not in S

And all combinations of tuples of T and S tuples are in R

\ (R \div S = \{t_r [X] |t_r \in R \and \pi _y (S) \sube y_x \}\)

Database Review Chapter II

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.