07 - Relational Data Models MDFD
07 - Relational Data Models MDFD
Course Leaders
Ami Rai E., Gp Capt N Rath VSM
[email protected], [email protected]
1
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions - Summary
2
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions – Summary [Contd…
• Formally,
Cartesian Product
Given: R(A1, A2, .........., An)
4
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions – 1 Page Summary
• Formally,
– Given R(A1, A2, .........., An)
– r(R) dom (A1) X dom (A2) X ....X dom(An)
6
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Topics
7
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Relational Data Model
• T 8
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Relational Model Concepts
• A relation typically contains a set of rows
– In the formal model, a table is called relation
• The data elements in each row represent certain facts that correspond to a real-
world entity or relationship
– In the formal model, a rows is called tuple
– Each row in the table represents a collection of related data values
• Each column has a column header that gives an indication of the meaning of the
data items in that column
– In the formal model, the column header is called an attribute name (or just attribute)
– All values in a column are of the same data type
9
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Relational Model Concepts contd.
• The table name and column names are used to help to interpret the meaning of the
values in each row
• For example, the table of Figure is called STUDENT because each row represents
facts about a particular student entity
The column names — Name, Student_number, Class, and Major — specify how to
interpret the data values in each row, based on the column each value is in
10
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Degree and Cardinality of a Relation
11
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Example of a Relation
Entity Set
12
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
DOMAIN
• A domain D is a set of atomic values
• By atomic, it means that
– each value in the domain is indivisible as far as the formal relational model is concerned
14
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Domain contd.
• Consider the relation
STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa)
• Using the data type of each attribute, the definition is sometimes written as
STUDENT(Name:string, Ssn:string, Home_phone: string, Address: string,
Office_phone:string, Age: integer, Gpa: real)
• we can specify the following previously defined domains for some of the attributes of
the STUDENT relation
dom(Name) = Names; dom(HomePhone) = USA_phone_numbers, dom(Office_phone) =
USA_phone_numbers, and dom(Gpa) = Grade_point_averages
• Example:
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
– CUSTOMER is the relation name defined over the four attributes: Cust-id, Cust-name,
Address, Phone#
– the domain of Cust-id is 6 digit numbers
16
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Tuple
• A tuple is an ordered set of values (enclosed in angled brackets ‘< … >’)
• Each value is derived from an appropriate domain
• For example:
– A row in the CUSTOMER relation is a 4-tupletis and would consist of four values
<632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000">
17
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Relation State
• A relation state r of the relation schema R(A1, A2, ..., An)
– also denoted by r(R)
– is a set of n-tuples r= {t1,t2,...,tm}
• The ith value in tuple t, which corresponds to the attribute Ai, is referred to as t[Ai] or
t.Ai (or t[i] if we use the positional notation)
• Of all the possible combinations, a relation state at a given time - the current
relation state - reflects only the valid tuples that represent a particular state of the
real world
• As the state of the real world changes, so does the relation state, by being
transformed into another relation state
• The schema R is relatively static and changes very infrequently 18
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Definition of Relation State using Set Theory
• A relation state r(R) is a mathematical relation of degree n on the domains dom(A1),
dom(A2), ..., dom(An), which is a subset of the Cartesian product (denoted by ×) of
the domains that define R
r(R) ⊆ (dom(A1)×dom(A2)×...×dom(An))
– The Cartesian product specifies all possible combinations of values from the underlying
domains
• The total number of values, or cardinality, in a domain D by |D| (assuming that all
domains are finite), the total number of tuples in the Cartesian product is |
dom(A1)|×|dom(A2)|×...×|dom(An)|
– This product of cardinalities of all domains represents the total number of possible
instances or tuples that can ever exist in any relation state r(R)
19
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions - Summary
• Formally,
– Given R(A1, A2, .........., An)
– r(R) dom (A1) X dom (A2) X ....X dom(An)
• L 21
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Definition Summary
Informal Terms Formal Terms
Table Relation
Column Header Attribute
All possible Column Domain
Values
Row Tuple
Table Definition Schema of a Relation
Populated Table State of the Relation
22
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Ordering of Tuples in A Relation
• O 23
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Ordering of Tuples in A Relation contd.
The relation STUDENT with same state but with different order of tuples
24
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Ordering of Values within a Tuple
• A 25
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Ordering of Values within a Tuple contd.
• T 26
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
NULL Values in the Tuple
• NULL values are used to represent the values of attributes that may be unknown or
may not apply to a tuple
27
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
NULL Values in the Tuple contd.
• Several meanings for NULL values, such as
– value unknown
– value exists but is not available, or
– attribute does not apply to this tuple(also known as value undefined)
28
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Summary
• A relation schema is a list of attributes that describe the structure of a relation
• A relation, or relation state, is a set of tuples that conforms to the schema
• Several characteristics differentiate relations from ordinary tables or files
• The first is that a relation is not sensitive to the ordering of tuples
• The second involves the ordering of attributes in a relation schema and the
corresponding ordering of values within a tuple
29
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences