Lecture 3.1 and 3.2 Relational Algebra
Lecture 3.1 and 3.2 Relational Algebra
Lecture 3.1 and 3.2 Relational Algebra
Database
Management
System
UNIT-II [10h]
Functional dependencies and Normalization: Functional dependencies, Decomposition, Full
Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued
Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization.
Database Security: Introduction, Threats, Counter Measures.
Control Structures: Introduction to conditional control, Iterative control and sequential control
statements, Cursors, Views.
3
University Institute of Engineering (UIE)
Department
Department
of Computer
of Computer
Science
Scienceand
andEngineering
Engineering (CSE)
(CSE)
Contents of the Syllabus
UNIT-III
[10h]
Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package body,
developing a package, Bodiless package, Advantages of packages.
Transaction Management and Concurrency Control: Introduction to Transaction Processing,
Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking
Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items.
4
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Chapter 1.3
Learning Objective
• To study relational algebra concepts,
selection ,projection ,relational calculus which helps in
understanding queries
• Fundamentals operations on Relational Algebra
• Tuple and Domain Relational Calculus
Learning Outcome
• Apply relational database theory, and be able to write
relational algebra expressions for queries
• Utilize the knowledge of basics of SQL and construct
queries using SQL
• Understanding relational algebra operators including
extended operators
Introduction
• Relational algebra
– Basic set of operations for the relational model
– More operational (procedural), very useful for representing
execution plans.
• Relational calculus
– Higher-level declarative language for specifying relational queries
– Lets users describe what they want, rather than how to compute
it: Non-operational, declarative.
Relational Algebra
• Relational algebra operations work on one or more relations to define
another relation without changing the original relations.
Relational Algebra
• Basic operations:
– Selection ( ) Selects a subset of rows from relation.
– Projection (
) Deletes unwanted columns from relation.
– Cross-product (
) Allows us to combine two relations.
– Set-difference (
– Union (
) Tuples in reln. 1, but not in reln. 2.
) Tuples in reln. 1 and in reln. 2.
• Additional operations:
– Intersection, join, division, renaming: Not essential, but (very!) useful.
13
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Projection
• col1, . . . , coln(R)
– Works on a single relation R and defines a relation that contains a
vertical subset of R, extracting the values of specified attributes and
eliminating duplicates.
– Deletes attributes that are not in projection list.
– Schema of result contains exactly the fields in the projection list,
with the same names that they had in the input relation.
– Projection operator has to eliminate duplicates!
Example - Projection
• Produce a list of salaries for all staff, showing only staffNo, fName,
lName, and salary details.
Union
• RS
– Union of two relations R and S defines a relation that contains all the
tuples of R, or S, or both R and S,
duplicate tuples being eliminated.
– R and S must be union-compatible.
Example - UNION
• List all cities where there is either a branch office or a property for rent.
city(Branch) city(PropertyForRent)
Set Difference
• R–S
– Defines a relation consisting of the tuples that are in relation R,
but not in S.
– R and S must be union-compatible.
city(Branch) – city(PropertyForRent)
Intersection
• RS
– Defines a relation consisting of the set of all tuples that are in both R
and S.
– R and S must be union-compatible.
Example - Intersection
• List all cities where there is both a branch office and at least one
property for rent.
city(Branch) city(PropertyForRent)
Cartesian product
• RXS
– Defines a relation that is the concatenation of every tuple of
relation “R with every tuple of relation S”
24
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Cartesian product and Selection can be reduced to a single operation called a Join.
25
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Join Operations
• JOINs can be used to combine tables
26
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Join Operations
• Various forms of join operation
– JOIN (Inner Join) : Return rows when there is at least one match
in both tables
– LEFT JOIN(Left Outer Join): Return all rows from the left
table, even if there are no matches in the right table
– RIGHT JOIN(Right Outer Join): Return all rows from the right
table, even if there are no matches in the left table
– FULL JOIN: Return rows when there is a match in one of the
tables
27
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Left Join
Right Join
Full Join
FAQ
1. How does Tuple-oriented relational calculus differ from domain-
oriented relational calculus?
2. Define Relational Algebra and Relational Calculus
3. What is degree of a Relation?
4. What is a Relation Schema and a Relation?
5. List various Operators used in Relational Algebra and Calculus
6. Solve the given by relational algebra. The Relations are :
• Emp(empno,ename,sal,job,comm,deptno)
• Dept (deptno,dname,dloc)
• Create a query to list unique jobs that are in deptno 30 and include the
location of department 30 in output
References
OTHER REFRENCES
• https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf
• http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf
• https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf
• http://www.nyu.edu/classes/jcf/CSCI-GA.2433-001_fa11/slides/session5/RelationalAlgebra-
RelationalCalculus-SQL.pdf
• https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf
• DatabaseSystemConceptsbySudarshan,Korth(McGraw-HillEducation)
• FundamentalsofDatabaseSystemByElmasari&Navathe-PearsonEducation
• http://ecomputernotes.com/database-system/rdbms
• https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
• https://www.studytonight.com/dbms/rdbms-concept
SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The
Benjamin / Cummings Publishing Co.
• Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.