The document discusses the relational model and relational algebra. It defines key concepts of the relational model such as relations, tuples, attributes, domains, relation schemas, and relational states. It also covers characteristics of relations, key constraints, null values, entity integrity, referential integrity, and foreign keys. The document then introduces relational algebra, its operations including selection, projection, join, set operations, and provides examples of queries using these operations.
The document discusses relational algebra operations. It defines the select, project, cartesian product, and join operations. It provides examples of relational algebra expressions using these operations on sample relations to retrieve specific tuples based on conditions.
3._Relational_Algebra.pptx:Basics of relation algebraZakriyaMalik2
Relational algebra is a set of operations used to specify queries in relational databases. There are unary operations like selection and projection that operate on a single relation, and binary operations like join, union, and difference that combine two relations. Aggregate functions can also be applied to compute values like count, sum, average, minimum and maximum over groups of tuples. A sequence of relational algebra operations forms an expression that represents the query.
Relational algebra is a set of operations used to specify queries on relational databases. The basic operations include select, project, join, union, intersection, and cartesian product. A sequence of relational algebra operations forms a query that manipulates relations and returns a relation of results. Common uses of the operations include retrieving subsets of tuples, projecting columns, joining tables, and set operations to combine relations.
Relational databases use relational algebra and relational calculus to manipulate data. Relational algebra consists of operations like select, project, join, and divide that take relations as inputs and outputs. Relational calculus specifies queries using predicates and quantifiers without describing how to retrieve data. Structured Query Language (SQL) is the standard language used to communicate with relational database management systems. SQL allows users to define schemas, retrieve, insert, update, and delete data.
This document provides an overview of relational algebra and SQL. It discusses key concepts such as relational query languages, relational algebra operators like selection, projection, join, and division. It also covers how SQL corresponds to relational algebra, with SQL using a declarative syntax while relational algebra is procedural. Common queries involving joins, aggregates, and other features are demonstrated in both SQL and equivalent relational algebra expressions.
The document discusses relational algebra and relational query languages. It provides an overview of SQL and relational algebra, including their differences. It describes the basic relational algebra operators like select, project, union, and join. It provides examples of how to express queries using these operators and how relational algebra expressions are used internally by databases to evaluate SQL queries.
The document discusses relational algebra operations. It defines the select, project, cartesian product, and join operations. It provides examples of relational algebra expressions using these operations on sample relations to retrieve specific tuples based on conditions.
3._Relational_Algebra.pptx:Basics of relation algebraZakriyaMalik2
Relational algebra is a set of operations used to specify queries in relational databases. There are unary operations like selection and projection that operate on a single relation, and binary operations like join, union, and difference that combine two relations. Aggregate functions can also be applied to compute values like count, sum, average, minimum and maximum over groups of tuples. A sequence of relational algebra operations forms an expression that represents the query.
Relational algebra is a set of operations used to specify queries on relational databases. The basic operations include select, project, join, union, intersection, and cartesian product. A sequence of relational algebra operations forms a query that manipulates relations and returns a relation of results. Common uses of the operations include retrieving subsets of tuples, projecting columns, joining tables, and set operations to combine relations.
Relational databases use relational algebra and relational calculus to manipulate data. Relational algebra consists of operations like select, project, join, and divide that take relations as inputs and outputs. Relational calculus specifies queries using predicates and quantifiers without describing how to retrieve data. Structured Query Language (SQL) is the standard language used to communicate with relational database management systems. SQL allows users to define schemas, retrieve, insert, update, and delete data.
This document provides an overview of relational algebra and SQL. It discusses key concepts such as relational query languages, relational algebra operators like selection, projection, join, and division. It also covers how SQL corresponds to relational algebra, with SQL using a declarative syntax while relational algebra is procedural. Common queries involving joins, aggregates, and other features are demonstrated in both SQL and equivalent relational algebra expressions.
The document discusses relational algebra and relational query languages. It provides an overview of SQL and relational algebra, including their differences. It describes the basic relational algebra operators like select, project, union, and join. It provides examples of how to express queries using these operators and how relational algebra expressions are used internally by databases to evaluate SQL queries.
Relational Algebra is a procedural query language that provides a theoretical foundation for relational databases and SQL. It defines several relational operations including selection, projection, union, intersection, difference, rename, and join. The main join operations in SQL are inner join, left join, right join, and full join which allow combining data from two or more tables based on matching column values.
The document discusses the relational model of data, which was proposed by Edgar F. Codd in the 1970s. It presents the key concepts of the relational model including relation schemes, relation instances, keys, foreign keys, and referential integrity constraints. It also introduces relational algebra operations such as select, project, join, and set operations that allow querying of relational databases and provides examples to illustrate how they work. Finally, it discusses how relational algebra provides the foundation for query optimization and execution in relational database management systems.
What is Relational model
Characteristics
Relational constraints
Representation of schemas
characteristics and Constraints of Relational model with proper examples.
Updates and dealing with constraint violations in Relational model
The document discusses relational algebra and operations that can be performed on relations in a relational database. It describes unary operations like select and project that operate on a single relation, as well as binary operations like join, union, and difference that combine two relations. It also covers additional operations like aggregation, outer joins, and recursive closure that provide more advanced querying capabilities beyond the core relational algebra. The goal of relational algebra is to allow users to use a sequence of algebraic operations to specify database queries and retrieve relation data in a declarative manner.
Introduction to relational model, Terminologies, Types of keys, Relational Algebra, Fundamental operations, Additional operations, Extended operations, Null values, Modification of the database
The document discusses relational algebra operations including selection, projection, join, union, intersection, difference, and cartesian product. It provides examples of how to write queries using these operations, such as selecting tuples that satisfy certain conditions, extracting certain attributes, combining relations, and performing joins between relations. Key operations like selection, projection, equijoin and natural join are explained in detail with examples.
The document discusses relational algebra operations used in database management systems. It defines various unary and binary relational operations like selection, projection, rename, union, intersection, difference, cartesian product, and division. Examples are provided to demonstrate how to represent SQL queries using these relational algebra operations on given relations. The document also covers aggregate functions and natural join operation in relational algebra.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
Relational algebra is the basic set of operations for the relational model, including unary operations like selection and projection, binary operations like various join types, and set operations like union and intersection. Relational algebra operations manipulate relations and produce new relations, allowing users to specify database queries. Common operations include selection to filter tuples, projection to select attributes, equijoins to match tuples on equality conditions, and outer joins to retain non-matching tuples.
This document outlines key concepts about relational algebra and its role in database query languages. It discusses unary operators like selection and projection, as well as relational algebra expressions and queries. Relational algebra is described as an intermediate language used within database management systems to procedurally specify queries by describing the sequence of operators applied. The selection, projection, and rename unary operators are explained in detail through examples. The document also contrasts applying operators sequentially versus as a single expression, and provides additional examples of the rename operator.
The document discusses the SQL standard and its components. It describes how SQL is used to define schemas, manipulate data, write queries involving single or multiple tables, and perform other operations. Key topics covered include data definition language, data manipulation language, data types, integrity constraints, queries, subqueries, and set operations in SQL. Examples of SQL commands for creating tables, inserting data, and writing various types of queries are also provided.
The document discusses the relational model for databases. It describes the key components of the relational model including relations (tables), attributes (columns), tuples (rows), schemas, and constraints such as primary keys, candidate keys, and foreign keys. It provides examples of how to represent entities, relationships, and attributes from an ER diagram in a relational schema using tables, columns, primary keys and foreign keys. It also discusses techniques for decreasing the number of relations, handling composite/multi-valued attributes, weak entities, and inheritance relationships.
The document discusses various concepts related to relational databases including:
- Primary keys uniquely identify rows in a table. Foreign keys match values in other tables' primary keys.
- Relational databases represent data using relations which have a schema and instances consisting of tuples.
- Relational algebra operations like selection, projection, join, etc. allow querying relational data.
The document discusses relational algebra, which is a formalism for creating new relations from existing ones. It describes the five basic relational algebra operators - union, difference, selection, projection, and cartesian product. It also covers derived operators like intersection, joins (natural, equi-join, theta join, semi-join), and renaming. Examples are provided to illustrate each operator. Relational algebra is used to translate SQL queries into optimized execution plans.
The document discusses relational algebra and tuple relational calculus. It defines the basic operators of relational algebra including selection, projection, union, difference, Cartesian product, and rename. It provides examples of how to write queries using each operator. It also discusses tuple relational calculus, defining domains, predicates, quantifiers, and how to write safe queries using this calculus.
This document discusses the relational model and relational database concepts. It covers domains and relations, relational keys like primary keys, candidate keys, foreign keys and their rules. It also discusses relational operators, relational algebra, relational calculus, and the SQL language. Key types like alternate keys, candidate keys, compound keys, primary keys, superkeys, and foreign keys are defined. Relational algebra operations like selection, projection, renaming, union, intersection, difference, cartesian product, and join are explained. Tuple relational calculus and domain relational calculus are introduced. Examples of queries using relational algebra and calculus are provided. Components of SQL like DDL, DML, DCL are listed
This document discusses different concepts related to the relational model including domains and relations, relational data integrity, keys such as primary keys, candidate keys, foreign keys and their rules. It also discusses relational operators, relational algebra, relational calculus and SQL. Finally, it describes different types of relational algebra operations including unary operations like select, project and rename and binary operations like join, union, intersection, difference and cartesian product.
Relational Algebra is a procedural query language that provides a theoretical foundation for relational databases and SQL. It defines several relational operations including selection, projection, union, intersection, difference, rename, and join. The main join operations in SQL are inner join, left join, right join, and full join which allow combining data from two or more tables based on matching column values.
The document discusses the relational model of data, which was proposed by Edgar F. Codd in the 1970s. It presents the key concepts of the relational model including relation schemes, relation instances, keys, foreign keys, and referential integrity constraints. It also introduces relational algebra operations such as select, project, join, and set operations that allow querying of relational databases and provides examples to illustrate how they work. Finally, it discusses how relational algebra provides the foundation for query optimization and execution in relational database management systems.
What is Relational model
Characteristics
Relational constraints
Representation of schemas
characteristics and Constraints of Relational model with proper examples.
Updates and dealing with constraint violations in Relational model
The document discusses relational algebra and operations that can be performed on relations in a relational database. It describes unary operations like select and project that operate on a single relation, as well as binary operations like join, union, and difference that combine two relations. It also covers additional operations like aggregation, outer joins, and recursive closure that provide more advanced querying capabilities beyond the core relational algebra. The goal of relational algebra is to allow users to use a sequence of algebraic operations to specify database queries and retrieve relation data in a declarative manner.
Introduction to relational model, Terminologies, Types of keys, Relational Algebra, Fundamental operations, Additional operations, Extended operations, Null values, Modification of the database
The document discusses relational algebra operations including selection, projection, join, union, intersection, difference, and cartesian product. It provides examples of how to write queries using these operations, such as selecting tuples that satisfy certain conditions, extracting certain attributes, combining relations, and performing joins between relations. Key operations like selection, projection, equijoin and natural join are explained in detail with examples.
The document discusses relational algebra operations used in database management systems. It defines various unary and binary relational operations like selection, projection, rename, union, intersection, difference, cartesian product, and division. Examples are provided to demonstrate how to represent SQL queries using these relational algebra operations on given relations. The document also covers aggregate functions and natural join operation in relational algebra.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
The document discusses the relational model and how to map an entity-relationship schema to a relational schema. It covers key aspects of the relational model including relations, attributes, primary keys, foreign keys, and how to represent different entity types and relationship types as relations and attributes while preserving constraints and cardinalities. Examples are provided to illustrate mapping entity-relationship diagrams to equivalent relational schemas.
Relational algebra is the basic set of operations for the relational model, including unary operations like selection and projection, binary operations like various join types, and set operations like union and intersection. Relational algebra operations manipulate relations and produce new relations, allowing users to specify database queries. Common operations include selection to filter tuples, projection to select attributes, equijoins to match tuples on equality conditions, and outer joins to retain non-matching tuples.
This document outlines key concepts about relational algebra and its role in database query languages. It discusses unary operators like selection and projection, as well as relational algebra expressions and queries. Relational algebra is described as an intermediate language used within database management systems to procedurally specify queries by describing the sequence of operators applied. The selection, projection, and rename unary operators are explained in detail through examples. The document also contrasts applying operators sequentially versus as a single expression, and provides additional examples of the rename operator.
The document discusses the SQL standard and its components. It describes how SQL is used to define schemas, manipulate data, write queries involving single or multiple tables, and perform other operations. Key topics covered include data definition language, data manipulation language, data types, integrity constraints, queries, subqueries, and set operations in SQL. Examples of SQL commands for creating tables, inserting data, and writing various types of queries are also provided.
The document discusses the relational model for databases. It describes the key components of the relational model including relations (tables), attributes (columns), tuples (rows), schemas, and constraints such as primary keys, candidate keys, and foreign keys. It provides examples of how to represent entities, relationships, and attributes from an ER diagram in a relational schema using tables, columns, primary keys and foreign keys. It also discusses techniques for decreasing the number of relations, handling composite/multi-valued attributes, weak entities, and inheritance relationships.
The document discusses various concepts related to relational databases including:
- Primary keys uniquely identify rows in a table. Foreign keys match values in other tables' primary keys.
- Relational databases represent data using relations which have a schema and instances consisting of tuples.
- Relational algebra operations like selection, projection, join, etc. allow querying relational data.
The document discusses relational algebra, which is a formalism for creating new relations from existing ones. It describes the five basic relational algebra operators - union, difference, selection, projection, and cartesian product. It also covers derived operators like intersection, joins (natural, equi-join, theta join, semi-join), and renaming. Examples are provided to illustrate each operator. Relational algebra is used to translate SQL queries into optimized execution plans.
The document discusses relational algebra and tuple relational calculus. It defines the basic operators of relational algebra including selection, projection, union, difference, Cartesian product, and rename. It provides examples of how to write queries using each operator. It also discusses tuple relational calculus, defining domains, predicates, quantifiers, and how to write safe queries using this calculus.
This document discusses the relational model and relational database concepts. It covers domains and relations, relational keys like primary keys, candidate keys, foreign keys and their rules. It also discusses relational operators, relational algebra, relational calculus, and the SQL language. Key types like alternate keys, candidate keys, compound keys, primary keys, superkeys, and foreign keys are defined. Relational algebra operations like selection, projection, renaming, union, intersection, difference, cartesian product, and join are explained. Tuple relational calculus and domain relational calculus are introduced. Examples of queries using relational algebra and calculus are provided. Components of SQL like DDL, DML, DCL are listed
This document discusses different concepts related to the relational model including domains and relations, relational data integrity, keys such as primary keys, candidate keys, foreign keys and their rules. It also discusses relational operators, relational algebra, relational calculus and SQL. Finally, it describes different types of relational algebra operations including unary operations like select, project and rename and binary operations like join, union, intersection, difference and cartesian product.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
Physiology and chemistry of skin and pigmentation, hairs, scalp, lips and nail, Cleansing cream, Lotions, Face powders, Face packs, Lipsticks, Bath products, soaps and baby product,
Preparation and standardization of the following : Tonic, Bleaches, Dentifrices and Mouth washes & Tooth Pastes, Cosmetics for Nails.
How to Manage Your Lost Opportunities in Odoo 17 CRMCeline George
Odoo 17 CRM allows us to track why we lose sales opportunities with "Lost Reasons." This helps analyze our sales process and identify areas for improvement. Here's how to configure lost reasons in Odoo 17 CRM
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
2. Relational Model Concepts:
Relational Model represents the database
as a collection of relations.
In the RM terminology a row is called a
tuple.
Column is called an attribute and the
table is called a relation.
The value that can appear in each column
called a domain.
3. Domain-set of atomic value
Relation Schema-R-(A1,A2,A3….An)
D –domain of Ai-dom(Ai).
r®,r={t1,t2,t3…tn}
T=<v1,v2,…vn> vi,1<=i<=n,
Relational state:
dom(A1),dom(A2)….dom(An)
r®€(dom(A1)*dom(A2)*….dom(An))
5. Key Constraints and Constraints on
NULL
Key Constraint:
Candidate key:
1)Uniqueness
2)Irreduciblilty
Super key:t1[sk]<>t2[sk]
Relation r and a subset of attribute SK
{empno,empname}
Student(regno,name,add,pno,dob,gpa)
{regno,name}
9. Introduction
What is relational algebra?
Relational algebra is a collection of operations that
are used to manipulate the entire set of relations.
The output of any relational algebra operation is
always a relation.
What are the Operations?
Set operations like union, intersection, difference,
and Cartesian product.
Special operations like: Selection, Projection
Joins.
10. Relational Algebra (RA)
Relational algebra is developed by E. F. Codd
in 1971.
Relational algebra is a procedural language
i.e. An RA expression contains answers to
i. WHAT is to be retrieved?
ii. HOW it is to be retrieved? and
iii. WHERE it is stored?
RA is a paradigm in a relational domain.
It is used as an intermediatory language to
transform the non-procedural queries into
procedural queries.
11. Relational Query Languages
Query languages:
Allow manipulation and retrieval of data from a
database.
Relational model supports simple, powerful
QLs:
Strong formal foundation based on logic.
Allows for much optimization.
Query Languages != programming languages!
13. SSN Name BDate Addr Sex Salary SuperSSN DNo
1111 Deepak 5-Jan-62 Malleswaram M 22000 4444 1
2222 Nandagopal 10-Dec-60 Rajajinagar M 30000 4444 3
3333 Pooja 22-Jan-65 Indiranagar F 18000 2222 2
4444 Prasad 11-Jan-57 Rajajinagar M 32000 6666 3
5555 Reena 15-Jan-85 MG Road F 8000 4444 3
DNumber DName MgrSSN MgrStartDate
1 Admin 1111 23-Jan-2000
2 Research 2222 11-Aug-1995
3 Accounts 4444 7-Dec-1986
PNumber PName PLocation DNum
10 Library Management USA 2
20 ERP Chennai 1
30 Hospital Management Mumbai 3
40 Wireless Network London 2
Employee
Department
Project
Example Instances
14. Example Instances
sid bid
s2 b1
s1 b1
day
10/10/99
11/12/99
sid sname city
s1 Deepa bang
s2 Laxmi mang
s3 Roopa del
rating
7
8
10
Bid Bname city
Reservation
As R
Sailor
As S
Boat
As B
B1 star mang
B2 Water rat chennai
15. The SELECT operation ()
It is an Unary operator
The select operation retrieves a subset of tuples/
rows in a relation that satisfy a selection
condition.
Syntax: <selection-condition> (Relation)
The rows are filtered based on the selection
condition.
All COLUMNS of the relation will be displayed.
Hence, SELECTION retrieves ALL COLUMNS
but SUB_SET of ROWS.
16. Selection
One of the interesting properties of the selection
operation is that it is commutative. Therefore, all
the expressions shown below are equivalent,
condition-1 (condition-2 (R))
(condition-1 AND condition-2) (R)
condition-2 (condition-1 (R))
17. The SELECT operation ()
Query-1: Find the employees whose salary is greater than 10,000 rupees.
Salary > 10000 (Employee)
Query-2: Find the employees who work for department 3 and whose salary is
greater than 30,000 rupees.
Emp3 DNo = 3 (Employee)
Result Salary > 30000 (Emp3)
Or,
Result DNo = 3 and Salary > 30000 (Employee)
18. Result (DNo = 4 and Salary > 25000) OR
( DNo = 5 and Salary > 30000) (Employee)
EMP1<- (DNo = 4 and Salary > 25000)(Employee)
EMP2<- ( DNo = 5 and Salary > 30000) (Employee)
RESULT<-(EMP1) OR(EMP2)(EMPLOYEE)
19. Selection
sid sname age
28 Yamuna 35.0
rating
9
58 Roopa 35.0
10
rating > 8(SAILOR)
sname
Yamuna
rating
9
Roopa 10 sname, rating(S2) (rating > 8(S2))
List all sailors who have a rating more than 8
20. The Projection Operation ()
The projection operation is used to select only few /all the
columns from a relation.
<attributes> (Relation)
Query-5: List the name and salary of all the employees.
Name, Salary (Employee)
Query-6: Print the project name and their locations.
PName, PLocation (Project)
Query -7: Retrieve the Name and Salary of all employees working for
department 1.
Result Name, Salary (DNo = 1 (Employee))
22. Query-8: Find the name, address, and salary
of the employees who earn more than 25000
rupees.
Name, Salary, Addr (Salary > 25000 (Employee))
Query-9: List the name and the location of
the projects not controlled by department 2.
PName, PLocation (DNum ≠ 2) (Project))
24. Union Compatibility
Union Compatibility:
Let R and S be two relations with attributes (A1, A2, …, An) and (B1, B2,
….., Bn) respectively.
If R and S are to be Unioned, Intersectioned, Minused then, they shall
satisfy the following two rules:
Rule 1: The relations R and S shall have the same
degree. That is, the number of attributes of R and S
must be same.
Rule 2: The domain of the ith attribute of R and the
domain of the ith attribute of S shall be same.
dom(Ai) = dom(Bi), where, 1 i n.
25. Example
Query-10: Retrieve the SSN of all employees who either work in
department 3 or directly supervise an employee who works in 3.
Emp_Dept3 SSN (DNo = 3 (Employee))
Supervisors SuperSSN (DNo = 3 (Employee))
Result Emp_Dept3 Supervisors
Emp_Dept3 Supervisors
2222 4444
4444 6666
5555
Result
2222
4444
5555
6666
26. Intersection (∩)
The expression R ∩ S returns all common tuples that appear
in both the relations R and S.
Query-12: Find the first name and the last name of people
who are teachers as well as students.
FName LName Age FName LName Age
Susan Yao 18 Jennifer Amy 30
Ramesh Arvind 20 Nanda Sham 40
Joseph Antony 19 Ramesh Arvind 20
Jennifer Amy 30
Andy Perumal 21
Student Teacher
27. Difference
This operation, written as R – S (set difference) returns all
tuples that are in R but not in S.
Query-13: Find the students who are not teachers.
Result Student – Teacher
{Susan, Joseph, Andy}
Query-14: Find the teachers who are not students.
Result Teacher – Student
{Nandagopal}
28. Cartesian Product (×)
The Cartesian product or cross-product is a binary
operation that is used to combine two relations. Assuming
R and S as relations with n and m attributes respectively, the
Cartesian product, R × S can be written as,
R (A1, A2, …, An) × S (B1, B2, …, Bm)
The result of the above set operation is,
Q (A1, A2, …, An, B1, B2, …, Bm)
Where,
Degree (Q) = n + m
count(Q) = Number of tuples in R * Number of tuples in S.
29. Query-15: Find for each female employee, all
the names of her dependents.
Dependent
ESSN DependentName Sex BDate Relationship
1111 Pradeep M 05-Jul-63 Brother
3333 Sonali F 15-Aug-85 Daughter
3333 Rahul M 01-Jan-80 Son
4444 Miruthula F 02-Aug-83 Spouse
FemaleEmp SSN, Name (Sex = ‘F’ (Employee))
FemaleDeps FemaleEmp × Dependent
Result Name, DependentName (SSN = ESSN (FemaleDeps))
30. Cartesian Product
This concatenates
all tuples of second
operand relation to
each tuple of first
operand relation.
It is useful if the
tuples are to be
selected based on
the other tuple
values
E-no Ename Salary
001
003
004
Nupur
Poonam
Shiva
40000
41000
45000
E-no Ename Salary
005
006
010
Shanta
Indu
Arif
40000
42000
45000
Bemployee
Memployee
33. Natural Join (*)
When we omit the condition during joining of two relations,
then it is called as natural join (*).
When we use the word join, it invariably means natural join.
We shall formally define natural join as:
Let R and S be the two relations with the attributes as shown
below:
R(X1, X2, .., Xm, Y1, Y2, …, Yn) and
S(Y1, Y2, …, Yn , Z1, Z2, …, ZP)
Example:
Employee (SSN, Name, Addr, DNo)
Department (DNo, DName)
35. Natural Join
For the natural Join, both operand relations
need to contain at least one attribute-
domain-pair common. The resultant relation
contains the concatenation of all the tuples of
first operand relation with second operand
relation, based on the common attribute
values.
The resultant relation has the union of
attributes of both operand relations.
36. Natural Join
Consider the Schema:
EMP(eno, ename, age)
WORKS-IN(eno, dno)
DEPT(dno, dname, address)
1. Find names of employees who work in department #2.
ename (σdno=2 (E) ⋈ W )
W.eno = E.eno
2. Find names of employees who work in a department in
Bombay
ename(σaddress=Bombay (E ) ⋈ W.eno = E.eno W ⋈ W.eno = E.eno D)
37. 3. Find the names of cities for departments in which Ravi
works:
city(σename = Ravi (E) W ⋈ D)
4. Find the names of employees who work in at least one
department
ename(E) ⋈ W)
5. Find the names of employees who work in all departments
ename ((eno,dno(W) / dno((D)) ⋈ E)
38. 6. Find the names of employees who work in all departments
in Bombay
T1:= eno,dno(E)/ dno(σcity=Bombay(W ⋈ D)
ename(T1 ⋈ E)
7. Find names of employees who work in a department which
is in Bombay or Delhi
T1:= σcity=Bombay (D) U σcity = Delhi (D)
ename(T1 ⋈ W ⋈ E)
39. 8 .Find names of employees who work in a department
in Bombay and a department in Delhi:
T1:= ename(σcity=Bombay (D) ⋈ W ⋈ E)
T2:= ename(σcity=Delhi (D) ⋈ W ⋈ E)
T1 ∩ T2
9. Find employee number of employees who do not work in
dno #2
eno(E) -- eno((σdno=2 W))
10. Find eno’s for employees who work in two different
departments in Bombay:
eno(σW1.dno≠W2.dno σW1.city=W2.city(ρw1(W ⋈ D) X ρw2 (W
⋈ D))
40. Theta Join ()
Let R and S be two relations. Consider an
attribute x in R, and an attribute y in S. The
theta join of these two relations can be
written as,
R x y S
where indicates a valid relational operator.
41. Equijoin ( = )
The most widely used join operation is equijoin. As
discussed in the previous subsection, when is =,
this type of -join (a special case) is called
equijoin. We shall use the notation to denote
equijoin. The general form for this kind of join is,
R <Join_condition> S
<Join_condition> must always have = operator
42. Query-16: Retrieve the name and salary
of the manager of each department.
Managers Department MgrSSN = SSN Employee
Gnames Name, Salary (Managers)
Query-17: Find which project(s) and
location(s) Pooja is working on.
EmpPooja Name = 'Pooja' (Employee)
PoojaPrj EmpPooja SSN = ESSN WorksOn
Result Name, PName, PLocation (PoojaPrj WrksOn.PNo = Project.PNumber Project)
43. Outer Joins
Dangling tuples in Join
Usually, only a subset of tuples of each relation will actually
participate in a join, i.e. only tuples that match with the
joining attributes.
Tuples of a relation not participating in a join are called
dangling tuples.
How do we keep dangling tuples in the result of a join?
Use null values to indicate a no-join situation. There are three
types of outer joins
- left outer join
- right outer join and
- outer join (full outer join).
44. Left outer-join
R1 R2 is similar to a natural join but keep all dangling
tuples of R1.
Right Outer-Join
R1 R2 is similar to a natural join but keep all dangling
tuples of R2.
Outer Join (full outer-join)
R1 R2 is similar to a natural join but keep all dangling
tuples of both R1 and R2.
The advantages of outer join is to take the union of tuples
from two relations that are not union compatible.
45. Example
RegNo Name GPA Branch RegNo Amount Year
1BI01CS056 Pooja 5.6 CSE 1BI01CS056 10000 2002
1BI01ME067 Pallavi 8.9 MECH 1BI01IS001 20000 2003
1BI01CS045 Reena 9.5 CSE
1BI01IS001 Kumar 6.0 ISE
RegNo Name GPA Branch Amount Year
1BI01CS056 Pooja 5.6 CSE 10000 2002
1BI01ME067 Pallavi 8.9 MECH null null
1BI01CS045 Reena 9.5 CSE null null
1BI01IS001 Kumar 6.0 ISE 20000 2003
Students Awards
Students Awards
Dangling
tuples
46. Division
Consider two relations R and S. Assume that R has only two attributes
r1 and r2 and S has only one attribute r2 with the same domain as in
R. This is to ensure that the degree of the numerator is more than the
degree of the denominator. Now we shall define R / S as,
For each r1 value in R, consider the set of r2 values that appear in
tuples of R with that r2 value. If this set contains S, the r1 is in the
result of R / S.
One possible restriction in this definition is that every attribute in S
should be in R.
Alternatively, we can define R / S as,
For, R(a1, a2, …., an, b1, b2, …., bn) / S(b1, b2, …., bn) and
T = a1, a2, …., an (R), return the subset of T, say W, such that every
tuple in W × S is in R. W is the largest subset of T, such that,
(W × S) R
47. Example
Options
RegNo SubId
412 CS175
412 CS272
412 CS351
413 CS175
413 CS272
532 CS175
676 CS272
SubId
CS175
CS272
SubId
CS175
SubId
CS175
CS272
CS351
RegNo
412
413
RegNo
412
413
532
RegNo
412
Electives1 Electives2 Electives3
Options/Electives1 Options/Electives2 Options/Electives3
48. GROUPING AND AGGREGATE
FUNCTIONS
We shall define Function formally using the
symbol (pronounced as script F ) as,
grouping_attributes aggregate_functions (Relation)
The steps involved in the evaluation of this
function is,
Partition the relation into groups.
Apply aggregate function to each group.
Output group and aggregate values, one tuple per
group.
49. Query-18: Retrieve department number,
number of employees and their average
salary.
Result (DNo, N, AvgSal) DNo Count(SSN), Avg(Salary) (Employee)
R1(SSN,NO_OF_DEPENDENTS)ESSN
COUNT DEPENDENTNAME (DEPENDENT)
R2<- σ NO_OF_DEPENDENTS>=2(R1)
R3<- LNAME,FNAME(R2*EMPLOYEE)
51. ER-to-Relational Mapping Algorithm
Step 1: Mapping of Regular Entity Types
Step 2: Mapping of Weak Entity Types
Step 3: Mapping of Binary 1:1 Relation Types
Step 4: Mapping of Binary 1:N Relationship Types.
Step 5: Mapping of Binary M:N Relationship Types.
Step 6: Mapping of Multivalued attributes.
Step 7: Mapping of N-ary Relationship Types.
52. ER-to-Relational Mapping
Algorithm
Step 1: Mapping of Regular Entity Types.
For each regular (strong) entity type E in the ER diagram,
create a relation R that includes all the simple attributes of E.
Choose one of the key attributes of E as the primary key for
R.
If the chosen key of E is composite, the set of simple
attributes that form it will together form the primary key of
R.
Example: We create the relations EMPLOYEE,
DEPARTMENT, and PROJECT in the relational schema
corresponding to the regular entities in the ER diagram.
SSN, DNUMBER, and PNUMBER are the primary keys for
the relations EMPLOYEE, DEPARTMENT, and PROJECT
as shown.
53. Step 2: Mapping of Weak Entity Types
For each weak entity type W in the ER schema with owner
entity type E, create a relation R & include all simple
attributes (or simple components of composite attributes) of
W as attributes of R.
Also, include as foreign key attributes of R the primary key
attribute(s) of the relation(s) that correspond to the owner
entity type(s).
The primary key of R is the combination of the primary
key(s) of the owner(s) and the partial key of the weak entity
type W, if any.
54. Example: Create the relation DEPENDENT in this step to
correspond to the weak entity type DEPENDENT.
Include the primary key SSN of the EMPLOYEE relation
as a foreign key attribute of DEPENDENT (renamed to
ESSN).
The primary key of the DEPENDENT relation is the
combination {ESSN, DEPENDENT_NAME} because
DEPENDENT_NAME is the partial key of DEPENDENT
55. Step 3: Mapping of Binary 1:1 Relation Types
For each binary 1:1 relationship type R in the ER schema,
identify the relations S and T that correspond to the entity
types participating in R.
There are three possible approaches:
1. Foreign Key approach: Choose one of the relations-say S-
and include a foreign key in S the primary key of T. It is better
to choose an entity type with total participation in R in the role
of S.
Example: 1:1 relation MANAGES is mapped by choosing
the participating entity type DEPARTMENT to serve in the
role of S, because its participation in the MANAGES
relationship type is total.
56. 2.Merged relation option: An alternate mapping of a 1:1
relationship type is possible by merging the two entity types
and the relationship into a single relation. This may be
appropriate when both participations are total.
3.Cross-reference or relationship relation option: The third
alternative is to set up a third relation R for the purpose of
cross-referencing the primary keys of the two relations S and
T representing the entity types.
57. Step 4: Mapping of Binary 1:N Relationship Types.
For each regular binary 1:N relationship type R, identify
the relation S that represent the participating entity type at
the N-side of the relationship type.
Include as foreign key in S the primary key of the relation
T that represents the other entity type participating in R.
Include any simple attributes of the 1:N relation type as
attributes of S.
Example: 1:N relationship types WORKS_FOR, CONTROLS,
and SUPERVISION in the figure.
For WORKS_FOR we include the primary key
DNUMBER of the DEPARTMENT relation as foreign key
in the EMPLOYEE relation and call it DNO.
58. Step 5: Mapping of Binary M:N Relationship Types.
For each regular binary M:N relationship type R, create a new
relation S to represent R.
Include as foreign key attributes in S the primary keys of the
relations that represent the participating entity types; their
combination will form the primary key of S.
Also include any simple attributes of the M:N relationship
type (or simple components of composite attributes) as
attributes of S.
59. Example: The M:N relationship type WORKS_ON from the
ER diagram is mapped by creating a relation WORKS_ON in
the relational database schema.
The primary keys of the PROJECT and EMPLOYEE
relations are included as foreign keys in WORKS_ON and
renamed PNO and ESSN, respectively.
Attribute HOURS in WORKS_ON represents the HOURS
attribute of the relation type. The primary key of the
WORKS_ON relation is the combination of the foreign key
attributes {ESSN, PNO}.
60. Step 6: Mapping of Multivalued attributes.
For each multivalued attribute A, create a new relation R.
This relation R will include an attribute corresponding to A,
plus the primary key attribute K-as a foreign key in R-of the
relation that represents the entity type of relationship type that
has A as an attribute.
The primary key of R is the combination of A and K. If the
multivalued attribute is composite, we include its simple
components.
Example: The relation DEPT_LOCATIONS is created.
The attribute DLOCATION represents the multivalued
attribute LOCATIONS of DEPARTMENT, while
DNUMBER-as foreign key-represents the primary key of the
DEPARTMENT relation.
The primary key of R is the combination of {DNUMBER,
DLOCATION}.
61. Step 7: Mapping of N-ary Relationship Types.
For each n-ary relationship type R, where n>2, create a new
relationship S to represent R.
Include as foreign key attributes in S the primary keys of the
relations that represent the participating entity types.
Also include any simple attributes of the n-ary relationship
type (or simple components of composite attributes) as
attributes of S.
Example: The relationship type SUPPY in the ER on the next
slide.
This can be mapped to the relation SUPPLY shown in the
relational schema, whose primary key is the combination of
the three foreign keys {SNAME, PARTNO, PROJNAME}
64. Summary of Mapping constructs and constraints
Correspondence between ER and Relational Models
ER Model Relational Model
Entity type “Entity” relation
1:1 or 1:N relationship type Foreign key (or “relationship” relation)
M:N relationship type “Relationship” relation and two foreign keys
n-ary relationship type “Relationship” relation and n foreign keys
Simple attribute Attribute
Composite attribute Set of simple component attributes
Multivalued attribute Relation and foreign key
Value set Domain
Key attribute Primary (or secondary) key
72. Retrieve the name of employess who
have no dependents
R1<-SSN(EMPLOYEE)
R2<-ESSN(DEPENDENT)
R3<-R1-R2
RESULT<-FNAME,LNAME(R3*EMPLOYEE)
73. List the names of managers who
have atleast one dependent
R1<-MGRSSN(DEPARTMENT)
R2<-ESSN(DEPENDENT)
R3<-R1∩R2
RESULT<-LNAME,FNAME(R3*EMPLOYEE)
74. Make a list of project numbers for project
that involve an employee who last name is
‘Smith’ ,either as a worker or as a manager
of the departments that controls the project.
R1<- SSN(LNAME=‘SMITH’(EMPLOYEE)
R2<- PNO(WORKS*R1)
R3<- DNO(R1⋈R1.SSN=DEPT.MGRSSN (DEPT))
R4<- DNO(LNAME=‘SMITH’(R3)
R5<- PNO(R3*PROJECT)
RESULT<-R2ᶸR5
75. For every project located in ‘Stafford’, list
the project number, the controlling dept
no and the dept manager’s last name,
address and birth date.
R1<- Ploc=‘Stafford’(Project)
R2<-(R1 ⋈DNUM=DNUMBER DEPARTMENT)
R3<-(R2 ⋈MGRSNN=SSN EMPLOYEE)
RESULT<-
PNO,DNUM,LNAME,ADD,BDATE(R3)
77. SAILORS BOAT
SID SNAME RATING AG
E
401 RAJ 10 25
402 RAVI 20 30
403 MAHESH 30 35
404 SATISH 40 40
BID BNAM
E
COLO
R
100 INTER
LAKE
RED
101 INTER
LAKE
GREEN
103 MARIN
E
RED
104 CLIPPE
R
GREEN
105 CLIPPE
R
BLACK
102 clipper brown
SID BID DAY
401 100 MONDAY
401 101 TUESDAY
402 102 WEDNES
DAY
403 103 MONDAY
RESERVE
78. 1.Find the names of sailors who
have reserved boat 103.
R1<- bid=103(Reserve)
R2<- sname(R1 ⋈sid=sid Sailors)
2.Find the names of sailors who have reserved a
red boat.
R1<- BID(COLOR=RED(BOAT))
R2<-(R1 ⋈BID=BID RESERVE)
R3<- NAME(R2 ⋈SID=SID (SAILORS))
79. 3.Find the names of sailors who
have reserved a red or green boat
R1<- COLOR=RED(BOAT)
R2<- SID(R1 ⋈Bid=Bid RESREVE)
R3<- COLOR=GREEN(BOAT)
R4<- SID(R1 ⋈Bid=Bid RESREVE)
R5<-R2ᶸR4
RESULT<- SNAME(R5*SAILORS)