3.1 Introduction To Relational Model
3.1 Introduction To Relational Model
[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
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
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
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
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
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
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)
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)))
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
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