DE Module2 RelationalModel PPT
DE Module2 RelationalModel PPT
PREPARED BY:
SIMANTIKA RAY
Structure of relational model:
The relational model uses a collection of tables to represent both data
and the relationships among those data.
Each table has multiple columns, and each column has a unique name.
Tables are referred to as relations, the rows as tuples or records and the
columns as attributes or fields.
Domain is the pool of values from which the actual values of a column
are drawn.
Relation (or tables)
It is a two dimensional array of rows and columns
containing single valued entries (entities) and no
duplicate rows.
Each cell can have only one value and no two rows may be
identical.
It is represented by combining attributes of the entities.
Domain
It is a set of permissible values that can be assigned to an
attributes.
Relation schema
It specifies the relation’s name, its attributes and the domain of each
attribute.
If R is the relation name and A1, A2, A3,……………. An is the list of attributes
Cardinality of a relation
It is the total number of tuples in a relation(i.e number of rows ina
table).
Relational Instance (or State)
Student
Tabular Representation of Weak Entity Sets
The weak Entity Set(W) is converted into a relation(R) ie
table, containing all simple attributes ie columns.
If a strong entity set (E) is owner of a weak entity set then
primary key of that strong entity set is also
included(which acts as a foreign key).
Now the combination of primary key of the strong entity
and key of weak entity acts as primary key for the weak
entity.
Tabular Representation of Relationship Sets
One-to-one relationship
If any attributes are present for the relationship R, then those are
also included.
One-to-Many Relationship / Many-to-one Relationship :
For each multivalued attribute A, create a new table containing the attribute
and the primary key as a foreign key.
The foreign key along with the attribute forms the primary key of the new
table.
Generalization and Specialization conversions:
All the specialized entity sets are converted to tables, if they are disjoint ie nothing
in common or no overlapping entities.
If they are overlapping then convert into an extra table.
1. Domain Constraints:
They specify that each attribute in a relation (ie table) must contain an
atomic value, only from the corresponding domain.
They are mainly created for defining the logically correct values for an
attribute of a relation.
2. Key Constraints
It states that the key attribute value in each tuple (ie record) must be
unique (ie no duplicates).
Integrity Constraints
Integrity refers to maintaining the consistency of data. Thus integrity
constraints ensures that changes made to the database doesn’t hamper
consistency.
key values.
The foreign key must exactly match with the values of primary key
in referenced relation( ie table) or it must be null.
RELATIONAL ALGEBRA
The relational algebra is a procedural query language.
It consists of a set of operations that take one or two relations as input and
produce a new relation as their result.
2. Relational Operations
Basic Set Operations
1. Union
2. Intersection
3. Set difference
4. Cartesian Product
Union( U ):
Example:
It is commutative ie R1 U R2 = R2 U R1
It is associative ie R1 U(R2UR3) = (R1 U R2) U R3
INTERSECTION(∩):
If R1 and R2 are two union compatible relations then R3 =
R1 ∩ R2 is the relation containing tuples(ie rows) that are
in both R1 and R2.
It is commutative ( ie R1 ∩ R2 = R2 ∩ R1)
It is associative ( ie R1 ∩(R2 ∩ R3 = (R1 ∩ R2) ∩ R3)
It is not commutative ie R1 − R2 ≠ R2 − R1
It is not associative ie R1 − (R2 − R3 )≠ (R1 − R2) − R3
Degree of resultant table is same as original tables
CARTESIAN PRODUCT ( X )
It is commutative ( ie R1 X R2 = R2 X R1)
It is associative ie R1 X (R2 X R3) = (R1 X R2) X R3)
Relational operations
2. PROJECT ( Π )
3. JOIN ( ⋈ )
The Select Operation
The select operation selects tuples that satisfy a given condition or predicate.
Example:
Result:
List the customer names who are either depositors or borrowers of the bank.
Inner Join
Equi Join
Natural Join
Non Equi Join
Theta Join
Self Join
Outer Join
Left Outer join
Right Outer Join
Full Outer Join
INNER JOIN
It retrieves all the combined tuples from the two relations,
which satisfy the join conditions.
Example:
Resultant relation:
Equi Join
It is a join in which equlity operator (ie. =) is only used
in each of the join conditions.
Non Equi join
It is a join in which any operator can be used, strictly
except the equality operator, in each of the join condition (ie
<=, >=, < , >, or ≠ ).
The converse of non equi join is equi join.
Theta Join
It is a join in which any operator can be used, including the
equality operator, in each of the join conditions (ie <=, >=, < ,
>, or ≠ ).
It is denoted as join condition Ɵ.
Example
Natural Join:
It requires that the attribute names used in the condition must be the same
in both the relations.
If the attribute names differ then the attribute name of one relation must be
renamed before applying natural join.
Result Relation
ρemployee(Emp)
Display the name of the sailors who have reserved a red color
boat.
Ans: ∏ Sname (Sailor *(Reserve * (бBcolor = ‘red’ (Boat))))
Find the name of the sailors who have reserved any boat.
Ans: ∏ Sname (Sailor * Reserve )
Find the name of the sailors who have reserved both a red
and a green color boat.
Ans: ∏ Sname (Sailor *(Reserve * (бBcolor = ‘red’ (Boat))))
∩
OUTER JOIN
Outer joins are used to retrieve additional tuples from one or both tables, even
though they don’t satisfy the join condition.
Display the details of all employees who may or may not be posted in any
branch along with employees who names are not uploaded in employee
register.
DIVISION ( ÷)
Generalized Projection
Aggregate Functions
Outer Join
Null Values∗∗
Generalized Projection
Avg
Count
Min
Max etc.
Display total credit spent by customers for every group of credit limit.
Question: Display the total credit spent and maximum credit spent for
every group of credit limit.
Answer:
Question: Display the total salary and maximum salary for every
department.
OUTER JOIN
Outer joins are used to retrieve additional tuples from one or both tables, even
though they don’t satisfy the join condition.
o or : (true or unknown)=true;
(false or unknown)=unknown;
(unknown or unknown)=unknown.
Join:
If two tuples from the participating tables have null value in common
attribute, then the tuples don’t match.
Project:
The projection operation treats nulls just like any other value when
eliminating duplicates.
If two tuples in the projection result are exactly the same, and both have
nulls in the same fields, they are treated as duplicates.
union,intersection,difference:
These operations treat tuples that have the same values on all fields as
duplicates even if some of the fields have null values in both tuples.
Aggregate:
When nulls occur in aggregated attributes, the operation deletes null
values at the outset, before applying aggregation.
Outer join:
For tuples that do not occur in the join result may be added to the result
padded with nulls.