0% found this document useful (0 votes)
37 views

07 - Relational Data Models MDFD

The document discusses relational data models and relational database concepts including schemas, relations, tuples, domains, cardinality, and degree. It provides examples and definitions of these concepts.

Uploaded by

Pritam Das
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

07 - Relational Data Models MDFD

The document discusses relational data models and relational database concepts including schemas, relations, tuples, domains, cardinality, and degree. It provides examples and definitions of these concepts.

Uploaded by

Pritam Das
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Relational Data Models

CSC311A - Database Systems


B. Tech. 2014

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

• R(A1, A2, …, An) is the Schema of a Relation


• R is the Name of the relation
• A1, A2, …, An are the Attributes of the relation

2
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions – Summary [Contd…

• r(R): a specific state (or "value" or “population”)


of relation R – this is a set of tuples (rows)
• r(R) = {t1, t2, …, tn} where each ti is the ith
tuple
• ti = <v1, v2, …, vn> where each vj element-of
dom(Aj)
3
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions – Summary [Contd…

• Formally,
Cartesian Product
Given: R(A1, A2, .........., An)

r(R)  dom (A1) X dom (A2) X ....X dom(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)

• R(A1, A2, …, An) is the schema of the relation


• R is the name of the relation
• A1, A2, …, An are the attributes of the relation
• r(R): a specific state (or "value" or “population”) of relation R – this is a set of tuples
(rows)
– r(R) = {t1, t2, …, tn} where each ti is an n-tuple
– ti = <v1, v2, …, vn> where each vj element-of dom(Aj)
5
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Objectives

• At the end of this lecture, student will be able to


– explain the concept of relational data models

6
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Topics

• Relational Model Concepts


• Characteristics of relations

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

• Degree (Meaning: No. of Attributes)


– The number of attributes in a relation determine the degree of the relation
– Example: A relation of degree seven, which stores information about university
students, would contain seven attributes describing each student as follows
STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa)

• Cardinality (Meaning: No. of Rows)


– The number of tuples in a relation is called the cardinality of the 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

• Some examples of domains


 Usa_phone_numbers - The set of ten-digit phone numbers valid in the United States
 Names - The set of character strings that represent names of persons
 Grade_point_averages - Possible values of computed grade point averages; each must be
a real (floating-point) number between 0 and 4
 Employee_ages - Possible ages of employees in a company; each must be an integer
value between 15 and 80
 Academic_department_names - The set of academic department names in a university,
such as Computer Science, Economics, and Physics 13
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Domain contd.

• A domain also has a data-type or a format defined for it


– The USA_phone_numbers may have a format: (ddd)ddd-dddd where each d is a decimal
digit and the first three digits form a valid telephone area code
– The data type for Employee_ages is an integer number between 15 and 80

• A domain is thus given a name, data type, and format


• Additional information for interpreting the values of a domain can also be given
– a numeric domain such as Person_weights should have the units of measurement, such
as pounds or kilograms

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

• It is also possible to refer to attributes of a relation schema by their position within


the relation
– second attribute of the STUDENT relation is Ssn,whereas the fourth attribute is Address
15
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Schema of a Relation
• The Schema (or description) of a Relation, R
– Denoted by R(A1, A2, .....An)
– R is the name of the relation
– The attributes of the relation are A1, A2, .....An
– Each attribute Ai is the name of a role played by some domain D in the relation schema R
– D is called the domain of Ai and is denoted by dom(Ai )

• 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

• Each n-tupletis (Columns/Attributes in a Table) is an ordered list of n values t


=<v1,v2, ..., vn>
where each value vi, 1 ≤ i ≤ n, is an element of dom (Ai) or is a special NULL value

• 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)

• R(A1, A2, …, An) is the schema of the relation


• R is the name of the relation
• A1, A2, …, An are the attributes of the relation
• r(R): a specific state (or "value" or “population”) of relation R – this is a set of tuples
(rows)
– r(R) = {t1, t2, …, tn} where each ti is an n-tuple
– ti = <v1, v2, …, vn> where each vj element-of dom(Aj)
20
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Formal Definitions - Example

• 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

• For example, in Figure in slide No.20


– some STUDENT tuples have NULL for their office phones because they do not have an
office (that is, office phone does not apply to these students)
– another student has a NULL for home phone, because either he does not have a home
phone or he has one but we do not know it (value is unknown)
– we can add an attribute Visa_status to the STUDENT relation that applies only to tuples
representing foreign students

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)

• A comparison of two NULL values leads to ambiguities


• Example
– if both Customer A and B have NULL addresses, it does not mean they have the same
address

• During database design, it is best to avoid NULL values as much as possible

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

You might also like