0% found this document useful (0 votes)
138 views7 pages

Dbms Seminar Report

This document discusses relational algebra and provides examples of queries using relational algebra operations on a sample database. Relational algebra allows efficient querying and manipulation of relational databases and is a foundation of modern database systems.

Uploaded by

deepikaumesh20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views7 pages

Dbms Seminar Report

This document discusses relational algebra and provides examples of queries using relational algebra operations on a sample database. Relational algebra allows efficient querying and manipulation of relational databases and is a foundation of modern database systems.

Uploaded by

deepikaumesh20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

CHAPTER 1
INTRODUCTION
Relational algebra serves as the foundation upon which modern database systems are
constructed, offering a systematic approach to querying and manipulating data. Within the
relational model, data is organized into tables (relations), and relational algebra provides a
set of operations to perform queries on these tables. Through operations such as selection,
projection, join, and set operations, users can formulate complex queries to extract
specific information from databases.

In the examples provided, we explore various scenarios where relational algebra


operations are applied to a sample database structure, illustrating the practicality and
versatility of this mathematical framework. By understanding and mastering relational
algebra, database practitioners can efficiently interact with databases, retrieve relevant
data, and derive valuable insights for decision-making and analysis.

DEPT. OF AIML, AIET 1|Page


DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

CHAPTER 2

EXAMPLES OF QUERIES IN RELATIONAL


ALGEBRA
The following are additional examples to illustrate the use of the relational algebra
operations. In general, the query can be stated in numerous ways using the various
operations [1]. We will state each query in one way and leave it to the reader to come up
with equivalent formulations. The SCHEMA of a COMPANY is given below.

EMPLOYEE (FNAME, MINIT, LNAME, SSN, BDATE, ADDRESS, SEX, SALARY,


SUPER_SSN, DNO)
DEPARTMENT (DNAME, DNUMBER, MGR_SSN, MGR_STRAT_DATE)
DEPT_LOCATIONS (DNUMBER, DLOCATION)
WORKS_ON (ESSN, PNO, HOURS)
PROJECT (PNAME, PNUMBER, PLOCATION, DNUM)
DEPENDENT (ESSN, DEPENDENT_NAME, SEX, BDATE, RELATIONSHIP)

QUERY 1. RETRIEVE THE NAME AND ADDRESS OF ALL EMPLOYEES WHO


WORK FOR THE ‘RESEARCH’ DEPARTMENT.

RESEARCH_DEPT ← σDname= ‘Research’(DEPARTMENT)


RESEARCH_EMPS ← (RESEARCH_DEPT Dnumber= DnoEMPLOYEE)
RESULT ← πFname, Lname, Address(RESEARCH_EMPS)

NOTE: Outer Union Is Equivalent to A Full Outer Join if the Join Attributes Are All the
Com Mon Attributes of The Two Relations. This query could be specified in other ways;
for example, the order of the JOIN and SELECT operations could be reversed, or the
JOIN could be replaced by a NATURAL JOIN after renaming one of the join attributes to
match the other join attribute name.

QUERY 2. FOR EVERY PROJECT LOCATED IN ‘STAFFORD’, LIST THE


PROJECT NUMBER, THE CONTROLLING DEPARTMENT NUMBER, AND
THE DEPARTMENT MANAGER’S LAST NAME, ADDRESS AND BIRTH DATE.

STAFFORD_PROJS ← σPlocation=‘Stafford’(PROJECT)
CONTR_DEPTS ← (STAFFORD_PROJS Dnum=DnumberDEPARTMENT)
PROJ_DEPT_MGRS ← (CONTR_DEPTS Mgr_ssn=SsnEMPLOYEE)

DEPT. OF AIML, AIET 2|Page


DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

RESULT ← πPnumber, Dnum, Lname, Address, Bdate(PROJ_DEPT_MGRS)

In this example, we first select the projects located in Stafford, then join them with their
controlling departments, and then join the result with the department managers. Finally,
we apply a project operation on the desired attributes.

QUERY 3. FIND THE NAMES OF EMPLOYEES WHO WORK ON ALL THE


PROJECTS CONTROLLED BY DEPARTMENT NUMBER 5.

DEPT5_PROJS ← ρ(Pno)(πPnumber(σDnum=5(PROJECT)))
EMP_PROJ ← ρ(Ssn, Pno)(πEssn, Pno(WORKS_ON))
RESULT_EMP_SSNS ← EMP_PROJ ÷ DEPT5_PROJS
RESULT ← πLname, Fname(RESULT_EMP_SSNS * EMPLOYEE)

In this query, we first create a table DEPT5_PROJS that contains the project numbers of
all projects controlled by department 5. Then we create a table EMP_PROJ that holds
(Ssn, Pno) tuples, and apply the division operation [2]. Notice that we renamed the
attributes so that they will be correctly used in the division operation. Finally, we join the
result of the division, which holds only Ssn values, with the EMPLOYEE table to retrieve
the Fname, Lname attributes from EMPLOYEE.

QUERY 4. MAKE A LIST OF PROJECT NUMBERS FOR PROJECTS THAT


INVOLVE AN EMPLOYEE WHOSE LAST NAME IS ‘SMITH’, EITHER AS A
WORKER OR AS A MANAGER OF THE DEPARTMENT THAT CONTROLS
THE PROJECT.

SMITHS(Essn) ← πSsn (σLname=‘Smith’(EMPLOYEE))


SMITH_WORKER_PROJS ← πPno(WORKS_ON * SMITHS)
MGRS ← πLname, Dnumber(EMPLOYEE Ssn=Mgr_ssnDEPARTMENT)
SMITH_MANAGED_DEPTS(Dnum) ← πDnumber (σLname=‘Smith’(MGRS))
SMITH_MGR_PROJS(Pno) ← πPnumber(SMITH_MANAGED_DEPTS * PROJECT)
RESULT ← (SMITH_WORKER_PROJS ∪ SMITH_MGR_PROJS)

In this query, we retrieved the project numbers for projects that involve an employee
named Smith as a worker in SMITH_WORKER_PROJS. Then we retrieved the project
numbers for projects that involve an employee named Smith as manager of the
department that controls the project in SMITH_MGR_PROJS. Finally, we applied the
UNION operation on SMITH_WORKER_PROJS and SMITH_MGR_PROJS. As a
single in-line expression, this query becomes
DEPT. OF AIML, AIET 3|Page
DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

πPno (WORKS_ON Essn=Ssn (πSsn (σLname=‘Smith’(EMPLOYEE))) ∪ πPno


((πDnumber (σLname=‘Smith’(πLname, Dnumber(EMPLOYEE)))
Ssn=Mgr_ssnDEPARTMENT)) Dnum-ber=DnumPROJECT)

QUERY 5. LIST THE NAMES OF ALL EMPLOYEES WITH TWO OR MORE


DEPENDENTS.

Strictly speaking, this query cannot be done in the basic (original) relational algebra [3].
We have to use the AGGREGATE FUNCTION operation with the COUNT aggregate
function. We assume that dependents of the same employee have distinct
Dependent_name values.

T1(Ssn, No_of_dependents)← Essn ℑ COUNT Dependent_name(DEPENDENT)


T2 ← σNo_of_dependents>2(T1)
RESULT ← πLname, Fname(T2 * EMPLOYEE)

QUERY 6. RETRIEVE THE NAMES OF EMPLOYEES WHO HAVE NO


DEPENDENTS.

This is an example of the type of query that uses the MINUS (SET DIFFERENCE)
operation.

ALL_EMPS ← πSsn(EMPLOYEE)
EMPS_WITH_DEPS(Ssn) ← πEssn(DEPENDENT)
EMPS_WITHOUT_DEPS ← (ALL_EMPS – EMPS_WITH_DEPS)
RESULT ← πLname, Fname(EMPS_WITHOUT_DEPS * EMPLOYEE)

We first retrieve a relation with all employee Ssns in ALL_EMPS. Then we create a table
with the Ssns of employees who have at least one dependent in EMPS_WITH_DEPS.
Then we apply the SET DIFFERENCE operation to retrieve employees Ssns with no
dependents in EMPS_WITHOUT_DEPS, and finally join this with EMPLOYEE to
retrieve the desired attributes. As a single in-line expression, this query becomes

πLname, Fname((πSsn(EMPLOYEE) – ρSsn(πEssn(DEPENDENT))) * EMPLOYEE)

QUERY 7. LIST THE NAMES OF MANAGERS WHO HAVE AT LEAST ONE


DEPENDENT.

MGRS(Ssn) ← πMgr_ssn(DEPARTMENT)
EMPS_WITH_DEPS(Ssn) ← πEssn(DEPENDENT)

DEPT. OF AIML, AIET 4|Page


DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

MGRS_WITH_DEPS ← (MGRS ∩ EMPS_WITH_DEPS)


RESULT ← πLname, Fname(MGRS_WITH_DEPS * EMPLOYEE)

In this query, we retrieve the Ssns of managers in MGRS, and the Ssns of employees with
at least one dependent in EMPS_WITH_DEPS, then we apply the SET INTERSECTION
operation to get the Ssns of managers who have at least one dependent. As we mentioned
earlier, the same query can be specified in many different ways in relational algebra [4].
In particular, the operations can often be applied in various orders.

DEPT. OF AIML, AIET 5|Page


DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

CHAPTER 3

CONCLUSION
Relational algebra exemplifies the elegance and efficiency of relational database
management, offering a standardized approach to data manipulation. Each example
discussed showcases the adaptability of relational algebra operations in solving different
data retrieval challenges, from selecting employees based on departmental affiliation to
identifying projects managed by specific departments.

As organizations increasingly rely on data-driven insights, proficiency in relational


algebra becomes a valuable asset for database administrators, analysts, and developers.
By leveraging the principles of relational algebra, users can navigate complex database
structures with ease, formulate precise queries, and unlock actionable insights from vast
amounts of data. In essence, relational algebra remains a cornerstone of database
management, empowering users to harness the full potential of relational databases for
informed decision-making and strategic planning.

DEPT. OF AIML, AIET 6|Page


DATABASE MANAGEMENT SYSTEMS / 21CS53 SEMINAR REPORT

REFERENCES
[1] https://mail.google.com/mail/u/0/tab=rm&ogbl#inbox/
FMfcgzGxSHlNLXjpwxvlDJTcbnSJmcXs?projector=1&messagePartId=0.1
[2] https://mail.google.com/mail/u/0/tab=rm&ogbl#inbox/
FMfcgzGxSHlNLZqdJNkwtrWjLxCpPBrL?projector=1&messagePartId=0.1
[3] https://mail.google.com/mail/u/0/tab=rm&ogbl#inbox/
FMfcgzGxSHlNLZqdTMnPhvLsGFhntjnJ?projector=1&messagePartId=0.1
[4] https://mail.google.com/mail/u/0/tab=rm&ogbl#inbox/
FMfcgzGxSHlNLZqmTgwsFjzChWvFBBzh?projector=1&messagePartId=0.1

DEPT. OF AIML, AIET 7|Page

You might also like