其他分享
首页 > 其他分享> > Lecture 03 Intro to Relational Model

Lecture 03 Intro to Relational Model

作者:互联网

Attribute

Attribute values are (normally) required to be atomic; that is, indivisible

The special value null is a member of every domain. Indicated that the value is “unknown”

The null value causes complications in the definition of many operations

 

Order of tuples is irrelevant (tuples may be stored in an arbitrary order)

Database schema -- is the logical structure of the database.

Database instance -- is a snapshot of the data in the database at a given instant in time.

schema:instructor (ID, name, dept_name, salary)

Instance:

 

 

Relational Query Languages:


Notation: σρ (r)

ρ is called the selection predicate

Defined as: σρ (r) = {t | t ∈ r and ρ(t)}

 

Project Operation:

 

where A1 , A2 are attribute names and r is a relation name

The result is defined as the relation of k columns obtained by erasing the columns that are not listed

 

Union Operation:

Notation: r ∪ s
Defined as: r ∪ s = {t | t ∈ r or t ∈ s}

For r ∪ s to be valid,

1. r, s must have the same arity (same number of attributes)

2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2 nd column of s)

 

Set Difference Operation:

Notation r – s

Defined as: r – s = {t | t ∈ r and t ∉ s}

Set differences must be taken between compatible relations.

r and s must have the same arity
attribute domains of r and s must be compatible

 

Intersection Operation:

Notation: r ∩ s
Defined as: r ∩ s = {t | t ∈ r and t ∈ s}

For r ∩ s to be valid.

1. r, s must have the same arity (same number of attributes)

2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2 nd column of s)

 

Cartesian-Product Operation:

Notation r x s
Defined as: r x s = {t q | t ∈ r and q ∈ s}

 

Assume that attributes of r(R) and s(S) are disjoint. (That is, R ∩ S = ∅).

If attributes of r(R) and s(S) are not disjoint, then renaming must be used.

 

 Example for renaming:

 

 

Renaming a Table:

Allows us to refer to a relation, (say E) by more than one name. ρ_x (E)

returns the expression E under the name X

 

Let r and s be relations on schemas R and S respectively.

Then, the “natural join” of relations R and S is a relation on schema R U S obtained as follows:

Consider each pair of tuples tr from r and ts from s.

If tr and ts have the same value on each of the attributes in R U S, add a tuple t to the result, where

 t has the same value as tr on r 

 t has the same value as ts on s

 

 

Each Query input is a table (or set of tables)
Each query output is a table.
All data in the output table appears in one of the input tables.

In summery,

 

 

标签:name,value,Intro,same,attributes,Lecture,Model,Operation,must
来源: https://www.cnblogs.com/M1stF0rest/p/16332741.html