Professional Documents
Culture Documents
INTRODUCTION
• Relational Model is the major data model for commercial
data processing applications. Data in the relational model
is represented by a relation. A relation consist of a
relational schema and relational instance.
• The relational schema consist of relation’s name, name
of each field and domain (range) of each field. For e.g.,
relational schema of students is shown below:-
• STUDENT (Rollno: integer, Name: string, Marks: integer,
Addr: string).
• A relational instance is a set of tuples (records) in which
each tuple has same number of fields as defined in the
relational schema.
EXAMPLE
DOMAIN
----- ----- ----- -----
----- ----- ----- -----
RELATION
102 B 81 H
TUPLES
103 C 82 I
(Records)
104 D 83 J
105 E 84 K
Fields (Attributes)
S2 3 S3 1 22
4 S4 2 21
5 S5 4 20
R1 1 11 10/09/2015
1 12 20/11/2015
UNION
• Union of two instances S1 and S2 returns a
relational instance, which contains all tuples that
occur in either s1 or s2 or both. Two relational
instances are called UNION compatible if they
have same number of fields. For e.g. S = S1 S2
SID SNAME RATING AGE
1 S1 2 35
2 S2 3 26
3 S3 1 22
4 S4 2 21
5 S5 4 20
INTERSECTION
• Intersection of two instances S1 and S2
returns a relational instance which contains all
tuples that occur in both instances. For e.g.
S= S1 ∩ S2
• Three types:
– Conditional or Theta Join
– Equi Join
– Natural Join
CONDITIONAL JOIN (Non-Equi Join)
A M A N A M A N
1 m NULL NULL 2 n 2 p
2 n 2 p NULL NULL 3 q
4 o NULL NULL NULL NULL 5 r
Full Outer Join
Full Outer Join
Left Outer Join
• The LEFT JOIN keyword returns all rows from the left table
(table1), with the matching rows in the right table (table2).
• The result is NULL in the right side when there is no match.
Emp Dept
ID State ID Division
1000 CA 1001 IT
1001 MA 1002 Sales
1002 TN 1003 Biotech
Left Outer Join: Emp Dept
E.ID = D.ID
ID State ID Division
1000 CA NULL NULL
1001 MA 1001 IT
1002 TN 1002 Sales
NULL NULL 1003 Biotech
RENAME OPERATOR
• Rename operator is used to avoid naming
conflicts. Rename operator is represented by .
DIVISION OPERATOR
• The division operator is useful for representing
same special type of queries like:- Find the
names of sailors who have reserved all boats.
DIVISION OPERATOR
• The division operator is useful for representing
same special type of queries like:- Find the
names of sailors who have reserved all boats.
Pitfalls in Relational Database Design
• Relational database design requires that we find a “good”
collection of relation schemas. A bad design may lead to:-
– Repetition of Information.
– Inability to represent certain information.
• Design Goals: