SlideShare a Scribd company logo
RELATIONAL DATA MODEL
PART 2
(Additional Notes)	
  
DFC2033 Database System
Course Learning Outcome
¨  CLO1 : Explain the fundamentals concepts of database management
and relational data model to create a database based on an
organization’s requirements.
¨  CLO3 : Solve an organization’s requirements by selecting the correct
database query formulation using an appropriate commercial
Database Management System (DBMS).
FP 304 – Database System
Learning Outcome
¨  Use operators of relational algebra.
¨  Identify the fundamental operators used to retrieve information from
a relational database.
¨  Describe the purpose and input of each of the operators.
¨  Use the operators to write the expressions based on given relational
tables.
¨  Show the output of the fundamental operators based on a given
database.
¨  Define the traditional set of operators for relational tables.
¨  Draw the Venn diagrams for traditional set operators.
¨  Define union compatibility.
¨  Apply the union, intersect, and difference set operators to two given
relational tables.
FP 304 – Database System
Relational Algebra
Relational Algebra is :
¨  The formal description of how a relational database operates
¨  An interface to the data stored in the database itself
¨  The mathematics which underpin SQL operations
¨  Operators in relational algebra are not necessarily the same as SQL
operators, even if they have the same name. For example, the SELECT
statement exists in SQL, and also exists in relational algebra. These two uses
of SELECT are not the same.
¨  The DBMS must take whatever SQL statements the user types in and translate
them into relational algebra operations before applying them to the
database.
FP 304 – Database System
Restrict (select)
¨  SELECT operation is used to select a subset of the tuples from a relation that
satisfy a selection condition.
¨  It is a filter that keeps only those tuples that satisfy a qualifying condition –
those satisfying the condition are selected while others are discarded.
¨  Symbol :
¤  σ (sigma) used to denote the SELECT operator
¤  (R) denote relation name.
¨  Syntax :
¤  σ<selection condition > ( R )
¤  Normally combine with {=,<,>, <=, >=, =}
FP 304 – Database System
Restrict (select)
¨  Symbol :
¤  σ (sigma) used to denote the SELECT operator
¤  (R) denote relation name.
¨  Syntax :
¤ σ<selection condition>( R )
¤  Normally combine with {=,<,>, <=, >=}
¨  May combine with Boolean Operator:
¤  AND
¤  OR
¤  NOT
FP 304 – Database System
Restrict (select)
¨  Example:
¤  To select the EMPLOYEE tuples whose department
number is four
	

¤  Select salary is greater than $30,000 the following
notation is used:
FP 304 – Database System
σDNO = 4 (EMPLOYEE)
σSALARY > 30,000 (EMPLOYEE)
¨  Select the tuples for all employees who either work
in department 4 and make over RM2500 per year,
or work in department 1 and make over RM3000.
FP 304 – Database System
Restrict (select)
σ(Dno=4 AND Salary>2500) OR (Dno=1 AND Salary>3000)(EMPLOYEE)
Example
Table : EMP_RESULT
FP 304 – Database System
EMP_RESULT ß σ(Dno=4 AND Salary>2500) OR (Dno=1 AND Salary>3000)(EMPLOYEE)
Project
¨  Project operation selects certain columns from the
table and discards the other columns.
¨  The PROJECT creates a vertical partitioning – one
with the needed columns (attributes) containing
results of the operation and other containing the
discarded Columns.
¨  Symbol -: Л (pi)
¨  Syntax : Л <attribute list> (R)	
  
FP 304 – Database System
Example
¨  List each employee’s staff number first, last name and salary.
STAFF_NEW ß  Л  staffNo,fname,lname,salary(STAFF)
FP 304 – Database System
Example
FP 304 – Database System
Table : STAFF_NEW
Project and select operators
¨  We can combine project with select operators when
we want to select certain column that specify
specific conditions.
¨  Example:
¤  Select student name and address for people who live in
Seremban.
¤  First : Select from temporary table who live in
Seremban
¤  Select : List name and address à temporary table
FP 304 – Database System
Example
Retrieve the first name, last name, salary and branch number of all employees
who work in branch B003.
The sequence is :
TEM_STAFF ßσbranchNo=B003(STAFF)
RESULT ß ЛFname,Lname,Salary,branchNo(TEMP_STAFF)
FP 304 – Database System
Example
TEM_STAFF ßσbranchNo=B003(STAFF)
RESULT ß ЛFname,Lname,Salary,branchNo(TEMP_STAFF)
You can also combine the operation as below:
ЛFname,Lname,Salary,branchNo(σbranchNo=B003(STAFF))
FP 304 – Database System
Exercise
¨  Using relational algebra
¤  Select Employee whose test score is greater than 91.
¤  List all the employee number, test code and score for test record.
¤  List all the test number, test code for employee number 110.
FP 304 – Database System
Table : Employee
Cross product
¨  This operation is used to combine tuples from two
relations in a combinatorial fashion.
¨  Concatenation of every tuple of relation R with
every tuple of relation S.
¨  Denoted by X
¨  R X S
¨  Syntax: (Л  <attributelist>(R))X (Л  <attributelist>(S))
FP 304 – Database System
Example
ClientNo fName lname
CR76 John Kay
CR56 Aline Stewart
CR74 Mike Ritchie
CR62 Mary Tregear
ClientNo propertyNo comment
CR56 PA14 Too small
CR76 PG4 Too remote
CR56 PG4
CR62 PA14 No dining room
CR56 PG36
TABLE: CLIENT TABLE: VIEWING
TABLE: RESULT
FP 304 – Database System
TABLE: RESULT
FP 304 – Database System
RESULT ß(Л  clientNo, fName, lName(Client)) X ((Л clientNo, propertyNo, comment (Viewing))
RESULT
Join
¨  Two relations R and S over all common attributes.
¨  One occurrence of each common attribute is eliminated from
the result.
¨  Symbol :
¨  Syntax:(Л  <attributelist>(R)) (Л  <attributlist> (R))
¨  Types of Join:
¤  Inner Join
¤  Outer Join
¤  Theta Join
¤  Natural Join
¤  Equi Join
¤  Semi Join
FP 304 – Database System
Please Find the definition
Inner join
¨  An INNER JOIN produces a result table containing
composite rows created by combining rows from two
tables where some join condition evaluates to true.
¨  Rows that do not satisfy the join condition will not
appear in the result table of an inner join.
¨  The inner join is the default join type, therefore the
keyword INNER is optional and may be omitted.
FP 304 – Database System
ClientNo fName lname
CR76 John Kay
CR56 Aline Stewart
CR74 Mike Ritchie
CR62 Mary Tregear
ClientNo propertyNo comment
CR56 PA14 Too small
CR76 PG4 Too remote
CR56 PG4
CR62 PA14 No dining room
CR56 PG36
TABLE: client TABLE: VIEWING
FP 304 – Database System
Example
Example
Client.ClientNo fname lname comment.ClientNo propertyNo comment
CR76 John Kay CR76 PG4 Too remote
CR56 Aline Stewart CR56 PA14 Too small
CR56 Aline Stewart CR56 PG4
CR56 Aline Stewart CR56 PG36
CR62 Mary Tregear CR62 PA14 No dining room
Result ß (Л  clientNo, fName, lName(Client)) (Л  clientNo, propertyNo, comment (Viewing))
TABLE: Result
FP 304 – Database System
Viewing.
Outer join
¨  There are two types of outer join:
¤  Left Outer Join
¤  Right Outer Join
FP 304 – Database System
Left outer join
¡  The left outer join operation keeps every tuple in the first
or left relation R in R and S;
¡  If no matching tuple is found in S, then the attributes of S
in the join result are filled with null values.
¡  Symbol :
FP 304 – Database System
Left outer join
Result ß (Л  P.PROJNO, PPROJNAME, DEPNO(Project)) Department
FP 304 – Database System
NullNull
Right outer join
¡  A similar operation with left outer join, right outer join,
keeps every tuple in the second or right relation S in the
result of R and S.
¨  Symbol :
FP 304 – Database System
Right outer join
Result ß (Л  P.PROJNO, PPROJNAME, DEPNO(Project)) Department)
FP 304 – Database System
NullNullNull
Traditional set operator from set theory
¨  There are 3 traditional set operator :
¤  Union
¤  Intersection
¤  Difference
Union
¨  Relation that includes all tuples that are either in R
or in S or in both R and S.
¨  Table must have the same number of attribute.
¨  Duplicate tuples are eliminated.
¨  Symbol : ∪
¨  Syntax :	
  Л  <attribute list>(R) ∪ Л  <attribute list>(R)
FP 304 – Database System
Union
FP 304 – Database System
Union
List all cities where there is in branch office or in property for rent.
Result1 ß Л  city(Branch)
Result2 ß Л  city(PropertyForRent)
Result_Union ß Result1 ∪ Result2
FP 304 – Database System
FP 304 – Database System
Result_Union ß	
  Л  city(Branch) ∪ Л  city(PropertyForRent)
Result
Union compatibility
¡  The operand relations R1(A1, A2, ..., An) and R2(B1, B2, ...,
Bn) must have the same number of attributes, and the
domains of corresponding attributes must be compatible;
that is, dom(Ai)=dom(Bi) for i=1, 2, ..., n.
¡  In other words, two relations are union compatibles if they
have the same degree and the
¡  same number attribute
¡  and domains
FP 304 – Database System
Union compatibility
¨  The relations below is said to be union compatibility
relation
FP 304 – Database System
Intersection
¨  Only those tuples that appear in both of the named
relation are given as an output result.
¨  The two operand must be type compatible.
¨  Symbol : ∩
¨  R ∩ S
¨  Syntax: Л  <attributelist>(R) ∩ Л  <attributelist>(R)
FP 304 – Database System
Intersection
FP 304 – Database System
Intersection
¨  List all cities where there is both a branch office and at least
one property for rent.
¨  Л  city(Branch) ∩ Л  city(PropertyForRent)
FP 304 – Database System
Difference
¨  Subtracts from the first named relation those tuples
that appear in the second named relation and
create a new relation.
¨  The two operand must be type compatible.
¨  Symbol : - (minus)
¨  Syntax: Л  <attributelist>(R) – Л<attributelist>(R)
FP 304 – Database System
Difference
FP 304 – Database System
Difference
¨  List all cities where there is a branch office but no properties for rent.
	
  Л  city(Branch) – Лcity(PropertyForRent)
FP 304 – Database System

More Related Content

PDF
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
PDF
Chapter 2 Relational Data Model-part1
PPTX
Dbms slides
PPT
Database Chapter 1
PDF
Fp304 DATABASE SYSTEM JUNE 2012
PPTX
The Relational Model
PPT
Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]
PDF
Database System Concepts and Architecture
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Chapter 2 Relational Data Model-part1
Dbms slides
Database Chapter 1
Fp304 DATABASE SYSTEM JUNE 2012
The Relational Model
Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]
Database System Concepts and Architecture

What's hot (20)

PPTX
Relational model
PDF
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
PPT
Software quality assurance lecture 1
PPTX
The Key Responsibilities of a Database Administrator
 
PPT
FDS (Sixth Edition) | C1 | Databases and Database Users
PDF
Relational database- Fundamentals
PPTX
Dbms Useful PPT
PPTX
Introduction to Database, Purpose of Data, Data models, Components of Database
PPT
Files Vs DataBase
PPT
Elmasri Navathe DBMS Unit-1 ppt
DOCX
Database approach
PDF
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
PPTX
Database user and administrator.pptx
PPT
data modeling and models
PPTX
ER DIAGRAM & ER MODELING IN DBMS
PPTX
System testing
PPTX
EFFECTIVE MODULAR DESIGN.pptx
PPTX
Unit1 dbms
PPT
Database Chapter 3
Relational model
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Software quality assurance lecture 1
The Key Responsibilities of a Database Administrator
 
FDS (Sixth Edition) | C1 | Databases and Database Users
Relational database- Fundamentals
Dbms Useful PPT
Introduction to Database, Purpose of Data, Data models, Components of Database
Files Vs DataBase
Elmasri Navathe DBMS Unit-1 ppt
Database approach
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Database user and administrator.pptx
data modeling and models
ER DIAGRAM & ER MODELING IN DBMS
System testing
EFFECTIVE MODULAR DESIGN.pptx
Unit1 dbms
Database Chapter 3
Ad

Viewers also liked (20)

PDF
Chapter 2 Relational Data Model-part 3
PDF
Chapter 1 Fundamentals of Database Management System
PDF
Chapter 3 Entity Relationship Model
PDF
4 the relational data model and relational database constraints
PPT
Fundamentals of Database system
PPTX
Database : Relational Data Model
PDF
Chapter 5 Database Transaction Management
PPTX
Oxford Scholarship Online Access
PDF
Software Engineering - 01. Introduction
PPTX
Chapter 6 relational data model and relational
PPTX
Fundamentals of database system - Relational data model and relational datab...
PPT
Ch01 database-conceptsppt4207
PDF
Software Engineering - Introduction and Motivation (Marcello Thiry)
PPTX
Database normalization
PPTX
M-tree Algorithm
PDF
Chapter 4 Structured Query Language
PPTX
10.m way search tree
PDF
Chapter3 the relational data model and the relation database constraints part2
PPTX
Transitioning from SQL to MongoDB
PPTX
Denormalization
Chapter 2 Relational Data Model-part 3
Chapter 1 Fundamentals of Database Management System
Chapter 3 Entity Relationship Model
4 the relational data model and relational database constraints
Fundamentals of Database system
Database : Relational Data Model
Chapter 5 Database Transaction Management
Oxford Scholarship Online Access
Software Engineering - 01. Introduction
Chapter 6 relational data model and relational
Fundamentals of database system - Relational data model and relational datab...
Ch01 database-conceptsppt4207
Software Engineering - Introduction and Motivation (Marcello Thiry)
Database normalization
M-tree Algorithm
Chapter 4 Structured Query Language
10.m way search tree
Chapter3 the relational data model and the relation database constraints part2
Transitioning from SQL to MongoDB
Denormalization
Ad

Similar to Chapter 2 Relational Data Model-part 2 (20)

PPTX
RDBMS
PPT
relational algebra and it's implementation
PPTX
Relational algebr
PPT
Relational Algebra
PPT
Unit04 dbms
PDF
1695304562_RELATIONAL_ALGEBRA.pdf
PPTX
Relational Database management Systems unit-II
PPT
Intro to relational model
PDF
4_RelationalDataModelAndRelationalMapping.pdf
PDF
Relational Database and Relational Algebra
PPT
Relational algebra.pptx
PPTX
Sql.pptx
PPTX
Intonation to SQL using the query language postgresSQL.pptx
PDF
Introduction to sql.pdf Database Systems
PPT
Preparing for BIT – IT2301 Database Management Systems 2001d
PPTX
database chapter 6.pptx advanced database
PPTX
Relational model
PPTX
Relational model
PPTX
Relational model
RDBMS
relational algebra and it's implementation
Relational algebr
Relational Algebra
Unit04 dbms
1695304562_RELATIONAL_ALGEBRA.pdf
Relational Database management Systems unit-II
Intro to relational model
4_RelationalDataModelAndRelationalMapping.pdf
Relational Database and Relational Algebra
Relational algebra.pptx
Sql.pptx
Intonation to SQL using the query language postgresSQL.pptx
Introduction to sql.pdf Database Systems
Preparing for BIT – IT2301 Database Management Systems 2001d
database chapter 6.pptx advanced database
Relational model
Relational model
Relational model

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Complications of Minimal Access Surgery at WLH
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Anesthesia in Laparoscopic Surgery in India
Complications of Minimal Access Surgery at WLH
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Insiders guide to clinical Medicine.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharma ospi slides which help in ospi learning
Week 4 Term 3 Study Techniques revisited.pptx
Supply Chain Operations Speaking Notes -ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program

Chapter 2 Relational Data Model-part 2

  • 1. RELATIONAL DATA MODEL PART 2 (Additional Notes)   DFC2033 Database System
  • 2. Course Learning Outcome ¨  CLO1 : Explain the fundamentals concepts of database management and relational data model to create a database based on an organization’s requirements. ¨  CLO3 : Solve an organization’s requirements by selecting the correct database query formulation using an appropriate commercial Database Management System (DBMS). FP 304 – Database System
  • 3. Learning Outcome ¨  Use operators of relational algebra. ¨  Identify the fundamental operators used to retrieve information from a relational database. ¨  Describe the purpose and input of each of the operators. ¨  Use the operators to write the expressions based on given relational tables. ¨  Show the output of the fundamental operators based on a given database. ¨  Define the traditional set of operators for relational tables. ¨  Draw the Venn diagrams for traditional set operators. ¨  Define union compatibility. ¨  Apply the union, intersect, and difference set operators to two given relational tables. FP 304 – Database System
  • 4. Relational Algebra Relational Algebra is : ¨  The formal description of how a relational database operates ¨  An interface to the data stored in the database itself ¨  The mathematics which underpin SQL operations ¨  Operators in relational algebra are not necessarily the same as SQL operators, even if they have the same name. For example, the SELECT statement exists in SQL, and also exists in relational algebra. These two uses of SELECT are not the same. ¨  The DBMS must take whatever SQL statements the user types in and translate them into relational algebra operations before applying them to the database. FP 304 – Database System
  • 5. Restrict (select) ¨  SELECT operation is used to select a subset of the tuples from a relation that satisfy a selection condition. ¨  It is a filter that keeps only those tuples that satisfy a qualifying condition – those satisfying the condition are selected while others are discarded. ¨  Symbol : ¤  σ (sigma) used to denote the SELECT operator ¤  (R) denote relation name. ¨  Syntax : ¤  σ<selection condition > ( R ) ¤  Normally combine with {=,<,>, <=, >=, =} FP 304 – Database System
  • 6. Restrict (select) ¨  Symbol : ¤  σ (sigma) used to denote the SELECT operator ¤  (R) denote relation name. ¨  Syntax : ¤ σ<selection condition>( R ) ¤  Normally combine with {=,<,>, <=, >=} ¨  May combine with Boolean Operator: ¤  AND ¤  OR ¤  NOT FP 304 – Database System
  • 7. Restrict (select) ¨  Example: ¤  To select the EMPLOYEE tuples whose department number is four ¤  Select salary is greater than $30,000 the following notation is used: FP 304 – Database System σDNO = 4 (EMPLOYEE) σSALARY > 30,000 (EMPLOYEE)
  • 8. ¨  Select the tuples for all employees who either work in department 4 and make over RM2500 per year, or work in department 1 and make over RM3000. FP 304 – Database System Restrict (select) σ(Dno=4 AND Salary>2500) OR (Dno=1 AND Salary>3000)(EMPLOYEE)
  • 9. Example Table : EMP_RESULT FP 304 – Database System EMP_RESULT ß σ(Dno=4 AND Salary>2500) OR (Dno=1 AND Salary>3000)(EMPLOYEE)
  • 10. Project ¨  Project operation selects certain columns from the table and discards the other columns. ¨  The PROJECT creates a vertical partitioning – one with the needed columns (attributes) containing results of the operation and other containing the discarded Columns. ¨  Symbol -: Л (pi) ¨  Syntax : Л <attribute list> (R)   FP 304 – Database System
  • 11. Example ¨  List each employee’s staff number first, last name and salary. STAFF_NEW ß  Л  staffNo,fname,lname,salary(STAFF) FP 304 – Database System
  • 12. Example FP 304 – Database System Table : STAFF_NEW
  • 13. Project and select operators ¨  We can combine project with select operators when we want to select certain column that specify specific conditions. ¨  Example: ¤  Select student name and address for people who live in Seremban. ¤  First : Select from temporary table who live in Seremban ¤  Select : List name and address à temporary table FP 304 – Database System
  • 14. Example Retrieve the first name, last name, salary and branch number of all employees who work in branch B003. The sequence is : TEM_STAFF ßσbranchNo=B003(STAFF) RESULT ß ЛFname,Lname,Salary,branchNo(TEMP_STAFF) FP 304 – Database System
  • 15. Example TEM_STAFF ßσbranchNo=B003(STAFF) RESULT ß ЛFname,Lname,Salary,branchNo(TEMP_STAFF) You can also combine the operation as below: ЛFname,Lname,Salary,branchNo(σbranchNo=B003(STAFF)) FP 304 – Database System
  • 16. Exercise ¨  Using relational algebra ¤  Select Employee whose test score is greater than 91. ¤  List all the employee number, test code and score for test record. ¤  List all the test number, test code for employee number 110. FP 304 – Database System Table : Employee
  • 17. Cross product ¨  This operation is used to combine tuples from two relations in a combinatorial fashion. ¨  Concatenation of every tuple of relation R with every tuple of relation S. ¨  Denoted by X ¨  R X S ¨  Syntax: (Л  <attributelist>(R))X (Л  <attributelist>(S)) FP 304 – Database System
  • 18. Example ClientNo fName lname CR76 John Kay CR56 Aline Stewart CR74 Mike Ritchie CR62 Mary Tregear ClientNo propertyNo comment CR56 PA14 Too small CR76 PG4 Too remote CR56 PG4 CR62 PA14 No dining room CR56 PG36 TABLE: CLIENT TABLE: VIEWING TABLE: RESULT FP 304 – Database System
  • 19. TABLE: RESULT FP 304 – Database System RESULT ß(Л  clientNo, fName, lName(Client)) X ((Л clientNo, propertyNo, comment (Viewing)) RESULT
  • 20. Join ¨  Two relations R and S over all common attributes. ¨  One occurrence of each common attribute is eliminated from the result. ¨  Symbol : ¨  Syntax:(Л  <attributelist>(R)) (Л  <attributlist> (R)) ¨  Types of Join: ¤  Inner Join ¤  Outer Join ¤  Theta Join ¤  Natural Join ¤  Equi Join ¤  Semi Join FP 304 – Database System Please Find the definition
  • 21. Inner join ¨  An INNER JOIN produces a result table containing composite rows created by combining rows from two tables where some join condition evaluates to true. ¨  Rows that do not satisfy the join condition will not appear in the result table of an inner join. ¨  The inner join is the default join type, therefore the keyword INNER is optional and may be omitted. FP 304 – Database System
  • 22. ClientNo fName lname CR76 John Kay CR56 Aline Stewart CR74 Mike Ritchie CR62 Mary Tregear ClientNo propertyNo comment CR56 PA14 Too small CR76 PG4 Too remote CR56 PG4 CR62 PA14 No dining room CR56 PG36 TABLE: client TABLE: VIEWING FP 304 – Database System Example
  • 23. Example Client.ClientNo fname lname comment.ClientNo propertyNo comment CR76 John Kay CR76 PG4 Too remote CR56 Aline Stewart CR56 PA14 Too small CR56 Aline Stewart CR56 PG4 CR56 Aline Stewart CR56 PG36 CR62 Mary Tregear CR62 PA14 No dining room Result ß (Л  clientNo, fName, lName(Client)) (Л  clientNo, propertyNo, comment (Viewing)) TABLE: Result FP 304 – Database System Viewing.
  • 24. Outer join ¨  There are two types of outer join: ¤  Left Outer Join ¤  Right Outer Join FP 304 – Database System
  • 25. Left outer join ¡  The left outer join operation keeps every tuple in the first or left relation R in R and S; ¡  If no matching tuple is found in S, then the attributes of S in the join result are filled with null values. ¡  Symbol : FP 304 – Database System
  • 26. Left outer join Result ß (Л  P.PROJNO, PPROJNAME, DEPNO(Project)) Department FP 304 – Database System NullNull
  • 27. Right outer join ¡  A similar operation with left outer join, right outer join, keeps every tuple in the second or right relation S in the result of R and S. ¨  Symbol : FP 304 – Database System
  • 28. Right outer join Result ß (Л  P.PROJNO, PPROJNAME, DEPNO(Project)) Department) FP 304 – Database System NullNullNull
  • 29. Traditional set operator from set theory ¨  There are 3 traditional set operator : ¤  Union ¤  Intersection ¤  Difference
  • 30. Union ¨  Relation that includes all tuples that are either in R or in S or in both R and S. ¨  Table must have the same number of attribute. ¨  Duplicate tuples are eliminated. ¨  Symbol : ∪ ¨  Syntax :  Л  <attribute list>(R) ∪ Л  <attribute list>(R) FP 304 – Database System
  • 31. Union FP 304 – Database System
  • 32. Union List all cities where there is in branch office or in property for rent. Result1 ß Л  city(Branch) Result2 ß Л  city(PropertyForRent) Result_Union ß Result1 ∪ Result2 FP 304 – Database System
  • 33. FP 304 – Database System Result_Union ß  Л  city(Branch) ∪ Л  city(PropertyForRent) Result
  • 34. Union compatibility ¡  The operand relations R1(A1, A2, ..., An) and R2(B1, B2, ..., Bn) must have the same number of attributes, and the domains of corresponding attributes must be compatible; that is, dom(Ai)=dom(Bi) for i=1, 2, ..., n. ¡  In other words, two relations are union compatibles if they have the same degree and the ¡  same number attribute ¡  and domains FP 304 – Database System
  • 35. Union compatibility ¨  The relations below is said to be union compatibility relation FP 304 – Database System
  • 36. Intersection ¨  Only those tuples that appear in both of the named relation are given as an output result. ¨  The two operand must be type compatible. ¨  Symbol : ∩ ¨  R ∩ S ¨  Syntax: Л  <attributelist>(R) ∩ Л  <attributelist>(R) FP 304 – Database System
  • 37. Intersection FP 304 – Database System
  • 38. Intersection ¨  List all cities where there is both a branch office and at least one property for rent. ¨  Л  city(Branch) ∩ Л  city(PropertyForRent) FP 304 – Database System
  • 39. Difference ¨  Subtracts from the first named relation those tuples that appear in the second named relation and create a new relation. ¨  The two operand must be type compatible. ¨  Symbol : - (minus) ¨  Syntax: Л  <attributelist>(R) – Л<attributelist>(R) FP 304 – Database System
  • 40. Difference FP 304 – Database System
  • 41. Difference ¨  List all cities where there is a branch office but no properties for rent.  Л  city(Branch) – Лcity(PropertyForRent) FP 304 – Database System