Relational Model
Relational Model
A Database model defines the logical design and structure of a database and
defines how data will be stored, accessed and updated in a database
management system. While the Relational Model is the most widely used
database model, there are other models too:
Hierarchical Model
Network Model
Relational Model
The table name and column names are helpful to interpret the meaning of
values in each row. The data are represented as a set of relations. In the
relational model, data are stored as tables. However, the physical storage of
the data is independent of the way the data are logically organized.
DB2 - IBM
Oracle - Oracle
Access – Microsoft
Domain constraints specify that within each tuple, and the value of each
attribute must be unique. This is specified as data types which include
standard data types integers, real numbers, characters, Booleans, variable
length strings, etc.
Example:
Key constraints
An attribute that can uniquely identify a tuple in a relation is called the key
of the table. The value of the attribute for different tuples in the relation has
to be unique.
Example:
1 Google Active
2 Amazon Active
3 Apple Inactive
Example:
Here, we will learn about the violations that can occur on a database as a
result of any changes made in the relation.
There are mainly four operations that have the ability to change the state of
relations, these modifications are given below:
Insert Operation
The insert operation gives values of the attribute for a new tuple which
should be inserted into a relation.
Update Operation
The update operation will modify the value which is already present in the
table
Delete Operation
Select Operation
Exercise:
Table Name – Employee Details
Relational Algebra
Relational Algebra is a set of basic operations used to manipulate the data in
relational model. These operations enable the user to specify basic retrieval
request. The result of retrieval is a new relation, formed from one or more
relations.
These operations can be classified in two categories:
Basic Set Operations
1) Union
2) Intersection
3) Set Difference (Minus)
4) Cartesian Product
Relational Operations
1) Select
2) Project
3) Join
4) Division
UNION
If R1 and R2 are two union compatible relations then R3 = R1 R2 is the
relation containing tuples that are either in R1 or in R2 or in both.
A B X Y A B
A1 B1 A1 B1 A1 B1
A2 B2 A7 B7 A2 B2
A3 B3 A3 B3 A3 B3
A4 B4 A5 B5 A4 B4
A7 B7
Intersection A5 B5
If R1 and R2 are two union compatible functions or relations, then the result
of R3 = R1 R2 is the relation that includes all tuples that are in both the
relations
Table R1 Table R2 Intersection Table R3
A B X Y A B
A1 B1 A1 B1 A1 B1
A2 B2 A7 B7 A3 B3
A3 B3 A3 B3 A4 B4
A4 B4 A4 B4
Set Difference
Table R1 Table R2
A B X Y
A1 B1 A1 B1
A2 B2 A7 B7
A3 B3 A3 B3
A4 B4 A4 B4
Difference (R1-R2)
A B
A2 B2
Difference (R2-R1)
A B
A7 B7
Cartesian Product
Cartesian Product If R1 and R2 are two functions or relations, then the result
of R3 = R1 R2 is the combination of tuples that are in R1 and R2.
Table R1 Table R2
A B C
A1 B1 C1
A2 B2 C2
A3 B3
A4 B4
Product
A B C
A1 B1 C1
A2 B2 C1
A3 B3 C1
A4 B4 C1
A1 B1 C2
A2 B2 C2
A3 B3 C2
A4 B4 C2
The project operation is used to select the records with specified attributes
while discarding the others based on some specific criteria. This is denoted
as .
Join
related tuples from two given relation join is used. This is denoted as ⋈. The
The JOIN operation is applied on two relations. When we want to select
join operation requires that both the joined relations must have at least one
domain compatible attributes.
Division
To perform the division operation R1 R2, R2 should be a proper subset of
R1.
Table R1 Table R2
A B B
A1 B1 B1
A1 B2 B2
A3 B1
A4 B2
A5 B1
A3 B2
R3=R1R2
A
A1
A3