0% found this document useful (0 votes)
45 views20 pages

3.1 Introduction To Relational Model

The document introduces some key concepts in relational databases: - A domain is a set of possible atomic values for an attribute. Examples include sets of names or identification numbers. - A data type describes the format or pattern of values in a domain. For example, the data type for PAN numbers specifies a 10-character string format. - A relation schema defines a relation by specifying its name and a set of attributes. For example, the Doctor relation schema contains attributes for ID, name, and specialty. - A relation is a set of tuples that conforms to a relation schema. It contains ordered sets of values, with one value for each attribute. The order of tuples does not matter, but the
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views20 pages

3.1 Introduction To Relational Model

The document introduces some key concepts in relational databases: - A domain is a set of possible atomic values for an attribute. Examples include sets of names or identification numbers. - A data type describes the format or pattern of values in a domain. For example, the data type for PAN numbers specifies a 10-character string format. - A relation schema defines a relation by specifying its name and a set of attributes. For example, the Doctor relation schema contains attributes for ID, name, and specialty. - A relation is a set of tuples that conforms to a relation schema. It contains ordered sets of values, with one value for each attribute. The order of tuples does not matter, but the
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Database Management Systems

[MCC511]
Winter, 2023-24

Lecture 3.1
Introduction to Relational Model
ABHISHEK KUMAR SINGH
ASSOCIATEPROFESSOR
DEPARTMENT OF MATHEMATICS & COMPUTING
IIT(ISM) DHANBAD
What we have done so far …
The first unit introduced you to the course
◦ It talked about what a DBMS is, and what does its architecture look like !!

The second unit was about capturing user requirements and preparing a high-level representation
◦ We saw how ER Diagram can be a tool for the same

The third unit is about using a particular data model at the Logical Level – the Relational Model
◦ It is an extension to the modelling activity where loose and vague requirements are refined

Recall that the Relational Model is one of the options available to you
◦ For example, there are other available options such as the OO Model and the Graph Model !!
◦ But the Relational Model is, by far, the most popular

We have not yet covered the transition part – how to convert an ER Model to a Relational Model
◦ We will do that at the end of this unit though

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Domain
A Domain is a collection of individual values, where each value is “atomic” in nature
◦ We discussed the term atomic with respect to attributes
◦ To extend the understanding consider all possible values that a particular “atomic attribute” may take …
◦ … this set forms a Domain of values

Examples of Domains:
◦ The set of valid Aadhaar Numbers
◦ The set of valid Permanent Account Numbers (PANs)
◦ The set of Names

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Data Type
A Data Type for a Domain describes the “look or shape” of the values
◦ In some cases, instead of a Data Type, we may have a Format

The values of a Domain follow some pattern or honour some criteria


◦ By capturing the same, we can express a generic form for all the values
◦ The Data Type or the Format for a Domain provides this information in a concise fashion

Examples of Data Types and Formats


◦ Data Type for Aadhaar Numbers is “12-digit integer not starting with a 1”
◦ Format for PANs is “10-character string with the first five and the last character being letters and
characters 6, 7, 8 and 9 being digits”
◦ Format for Names is “set of one or more characters, including spaces”

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Relation Schema
A Relation Schema is a collection of …
◦ … a Name called the Relation Name, and …
◦ … a set of Attributes, where an Attribute represents a specific name for a Domain in a specific context

More Formally, a Relation Schema R, represented as R(A1, A2, … An) …


◦ … represents an ordered collection of a value each from D1, D2, … Dn, where …
◦ … Ai is a name for the ith value in the collection, which plays a role in R

Example of Relation Schema


◦ Doctor(Id, Name, Speciality)
◦ Here, R is Doctor; A1 is Id; A2 is Name and A3 is Speciality

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Relation
A Relation r is an “unordered set” of “ordered set” of values of the form {d1, d2, … dn} …
◦ … where di ∈ Di and n is called the degree of the r

The Relation r, denoted by r(R), has an associated Relation Schema R(A1, A2, … An) …
◦ … where R denotes the name of the relation, and A1, A2, … An represent the attributes of the Relation

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

Assume that we have a Relation r(R) described


by the Relation Schema R(X, Y, Z) with
three ordered sets of values {x1, y1, z1},
{x2, y2, z2} and {x3, y3, z3}

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

Assume that we have a Relation r(R) described


by the Relation Schema R(X, Y, Z) with
three ordered sets of values {x1, y1, z1},
{x2, y2, z2} and {x3, y3, z3}

The order of the three sets within r does not


matter

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z
=
Thus, all these are equivalent forms of r
X Y Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z
x1 ∈ X y1 ∈ Y z1 ∈ Z
=
X Y Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x1 ∈ X y1 ∈ Y z1 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

This, however, is not equivalent to r – since the
order of the values within the ordered set has X Z Y
changed x1 ∈ X z1 ∈ Y y1 ∈ Z
x2 ∈ X z2 ∈ Y y2 ∈ Z
x3 ∈ X z3 ∈ Y y3 ∈ Z

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

This, however, is not equivalent to r – since the
order of the values within the ordered set has X Z Y
changed x1 ∈ X z1 ∈ Y y1 ∈ Z
x2 ∈ X z2 ∈ Y y2 ∈ Z
Having said that, this constraint is somewhat x3 ∈ X z3 ∈ Y y3 ∈ Z
relaxed when you use an RDBMS – you can
provide the values in a different order, but you
must explicitly define the order simultaneously

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
X Y Z
r(R) = R(X, Y, Z) x1 ∈ X y1 ∈ Y z1 ∈ Z
x2 ∈ X y2 ∈ Y z2 ∈ Z
x3 ∈ X y3 ∈ Y z3 ∈ Z

This, however, is not equivalent to r – since the
order of the values within the ordered set has X Z Y
changed x1 ∈ X z1 ∈ Y y1 ∈ Z
x2 ∈ X z2 ∈ Y y2 ∈ Z
Having said that, this constraint is somewhat x3 ∈ X z3 ∈ Y y3 ∈ Z
relaxed when you use an RDBMS – you can
provide the values in a different order, but you
must explicitly define the order simultaneously

We will see more on that when we cover SQL at depth

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Relation
A Relation r is an “unordered set” of “ordered set” of values of the form {d1, d2, … dn} …
◦ … where di ∈ Di and n is called the degree of the r

The Relation r, denoted by r(R), has an associated Relation Schema R(A1, A2, … An) …
◦ … where R denotes the name of the relation, and A1, A2, … An represent the attributes of the Relation

A special value, null, is considered to be an element of all Domains


◦ It represents either a “missing value” or a placeholder for “not applicable”

Example: Relation r with Relation Schema Doctor(Id, Name, Speciality)


Id Name Speciality
1 John Cardiologist
2 Mary Gynaecologist
3 Bob ENT Surgeon

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Some Definitions – Tuple
A Tuple is a single “ordered” set of values of the form {d1, d2, … dn}, where di ∈ Di
Thus, a Relation can also be defined as r = {t1, t2, … tn}, where ti is a tuple …
◦ … corresponding to the same Relation Schema (note that the order between any ti and tj doesn’t matter here)

A Tuple within a Relation represents a set of real-world information …


◦ … usually representing one specific real-world object

Example of a Tuple in Relation r:


Id Name Speciality
1 John Cardiologist
2 Mary Gynaecologist
3 Bob ENT Surgeon

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Set Theoretic Definition of a Relation
The definitions we saw could be considered “semi-formal”
The definition of a Relation is strongly connected to the Mathematical foundation of Set Theory
Formally, a Relation r(R) is a mathematical relation on the Domains denoted by dom(Ai), which is a
subset of the Cartesian Product of the Domains, where Ai is the ith Attribute of r,
◦ Mathematically, r(R) ⊆ ((dom(A1)) X (dom(A2)) X … X (dom(An)))

If the number of possible values in a Domain D is denoted by |D| …


◦ … the maximum number of tuples in r is given by |dom(A1)| * |dom(A2)| * … * |dom(An)|

Another Relation s(S)denoted by S(B1, B2, … Bm) is said to be (union) compatible with r(R) if
◦ m = n and,
◦ dom(Ai) = dom(Bi), for 1 ≤ i ≤ n
◦ Note that compatibility doesn’t necessarily imply equality, since r and s may have different set of Tuples

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Practical View of a Relation
A Relation should be seen as a collection of rows and columns
The rows are the Tuples, and their order within the relation does not matter
The columns are the Attributes, and their order within the relation matters
Since a Relation is essentially a Set, duplicates are disregarded …
◦ … thus, a Relation never contains duplicate Tuples
◦ This is one aspect where most RDBMSs do not concur with the theoretical Relational Model …
◦ … since they do allow duplicate data to be stored as part of the same relation

The operations over the data, thus, attempt to retrieve or manipulate rows and columns in a table
◦ We will see what are the ways to define these operations in different forms

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
What will we cover in this Unit?
We will cover how to represent data in the Relational Data Model …
◦ … i.e., we will start visualising our data in the form of rows and columns

We will see some Relational Query Languages at a glance


◦ A Relational Query Language helps with specifying operations over the data represented as a Relation

There are two types of Relational Query Languages that we will see in this course
◦ Non-procedural Languages help in specifying operations at an abstract level …
◦ … without actually detailing how the operations should be performed
◦ We will only touch upon these languages, since their practical applicability is low, in particular …
◦ … we will have a brief overview of two forms of a Relational Query Framework called Relational
Calculus
◦ Procedural Languages provide a step-by-step procedure to perform an operation
◦ We will cover the Relational Algebra as an example of this type – in somewhat depth !!

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
In the next Lecture …
We will start off with the Relational Algebra in the next Lecture
◦ Relational Algebra is more popular than Relational Calculus (thus, we will spend a little more time on that)

We will begin with the two most important operations in Relational Algebra
◦ These operations allow us to filter data horizontally and vertically as per our convenience
◦ This will also provide you with a theoretical foundation for usage of SQL …
◦ … which is a relational query language supported by the RDBMSs for performing operations over data

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Homework
The representation of the Relational Model that we usually discuss is based on three-valued logic
◦ Read about the three-valued logic, and the associated problem
◦ You can start by reading the NULL subsection of this section on Wikipedia:
https://en.wikipedia.org/wiki/Relational_model#SQL_and_the_relational_model

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Further Reading
Dig out the 1970 paper titled “A Relational Model of Data for Large Shared Data Banks” by E.F. Codd
◦ Read it to get a more formal understanding of the Relational Model
◦ It might clarify many doubts in your mind about what a relation looks like
◦ This is what comes up in the Google Search I made:
https://www.seas.upenn.edu/~zives/03f/cis550/codd.pdf

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD

You might also like