Chapter2 Relational Model
1.Structure of Relational Databases
1.1Basic Structure
On the logical level, relational database is a collection of 2-D tables called Relations
relations represents an entity set or a relationship set
A row of a relation represents a entity or a relationship
Each row of a relation can be referred to as tuple
Each column of a relation has a name. Named columns of a relation are referred to as attributes
Attribute values are (normally) required to be atomic; that is, indivisible
The set of allowed values for each attribute is called the domain of the attribute
The special value null is a member of every domain
Relation customer is a subset of: D1 ×D2×D3
Formally, given sets D1, D2, …. Dn a relation r is a subset of
*D*1 x *D*2 x … x *Dn*
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai $$\in$$ Di3
Cartesian Product
Tuple variable
- is a variable that stands for a tuple
- Whose domain is the set of all tuples of a particular relation
Relation Schema
- A1, A2, …, An are attribute names
- R = (A
1, A2, …, An) is a relation schema - r*(*R) denotes(表示) a relation r on the relation schema R
- The current values (relation instance) of a relation are specified by a table
Relations are Unordered
Order of tuples is irrelevant(无关紧要的;不相关的) (tuples may be stored in an arbitrary order)
A database consists of multiple relations
Information about an enterprise is broken up into parts, with each relation storing one part of the information
1.2Keys
K is a set of attributes, let K$$\subseteq$$ R
K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R)
Superkey K is a candidate key if K is minimal
Primary key:
- a candidate key chosen as the principal means of identifying tuples within a relation
- Should choose an attribute whose value never, or very rarely, changes.
Foreign Keys:
- A relation r1 may have an attribute that corresponds to the primary key of another relation r2. The attribute is called a foreign key
- r1 is referencing relation
- r2 is referenced relation
Schema Diagram
2.Fundamental Relational-Algebra-Operations
select: $$\sigma$$
project: $$\prod$$
union: $$\bigcup$$
set difference: –
cartesian product: $$\times$$
rename:$$\rho$$
3.Additional Relational-Algebra-Operations
•Set intersection $$\bigcap$$
•Natural join $$\bowtie$$
•Division $$\div$$
•Assignment $$\leftarrow$$
4.Extended Relational-Algebra-Operations
•Generalized Projection (广义投影)
•Aggregate Functions
•Outer Join
5.Null Values
•It is possible for tuples to have a null value, denoted by null, for some of their attributes
•null signifies an unknown value or that a value does not exist.
•The result of any arithmetic expression involving null is null
•Aggregate functions simply ignore null values (as in SQL)
•For duplicate elimination and grouping, null is treated like any other value, and two nulls are are assumed to be the same
•Comparisons with null values return the special truth value: unknown
•Result of select predicate is treated as false if it evaluates to unknown(选取空值)
6.Modification of the Database
•The content of the database may be modified using the following operations:
- –Deletion
- –Insertion
- –Updating
•All these operations are expressed using the assignment operator