Anda di halaman 1dari 5

DBMS

Lab # 11
27th April

M Shahum Sultan
Database Management System
Lab Task # 1:
Write relational algebra expression for the following queries:
1. Retrieve the name, job title and department number of all
employees whose job title is Clerk.
2. What is the name of the employee whose salary is greater
than 500?
3. Write an expression that combines all rows of table EMP and
table DEPT
Solution:
1. name, jobtitle, deptno(job title=CLERK(EMP))
2. name(salary>500)
3. EMP x DEPT

Lab Task # 2:

Consider the following scheme for a library


database
Author (authorname, citizenship, birthyear)
Book (isbn, title, authorname)
Topic (isbn, subject)
Branch (libname, city)
Instock (isbn, libname, quantity)

1. Create a table for the scheme above, insert some rows to


populate them
2. For the scheme given above write relational algebra
expressions for the following:
Give all authors born after 1940
Give the names of libraries in Sydney
Give the cities where each book is held
Give the title of each book on the topic of either alcohol
or drugs
Solution:
Author
authorname citizenship birthyear
John USA 1959
Micheal UK 1940
Oliver USA 1942

Book
isbn title authorname
1234 Control Alcohol Oliver
1235 Fault in Our Stars John

Topic
isbn subject
1234 Alcohol
1235 Thriller

Branch
libname city
New York Central Library New York
Sydney Central Library Sydney

Instock
isbn libname quantity
1234 New York Central 5
Library
1235 Sydney Central 3
Library

o authorname(birthyear>1940(Author))
o libname(city=Sydney(Branch))
o city(Branch Instock)
o title(Book) Book Book.isbn=Topic.isbn Topic subject=Alcohol or subject=Drugs

(Branch)
Lab Task # 3:
1. Write the relational algebra expression and SQL queries for
the following:
What is the name of the user whose age is greater than
25?
Retrieve the data from user where id is greater than
two and age is not equal to 31
Write an expression that combines all rows of table User
and Occupation
2. Write the relational algebra expression for the following
queries

Solution:
o name(age>25(User))
o id > 2 AND age 31(User)
o User x Occupation
o User Occupation City
o name, gender(User City.citname=Boston(City))

Lab Task # 4:
For the schema given above write relational algebra expressions
for the following:
1. What are the codes of all the subjects taught?
2. What are the names of all the students?
3. What are the names of students enrolled in cs3020?
4. Which subjects is Hector taking?
5. Who teaches cs1500?
6. Who teaches cs1500 or cs3020?
7. Who teaches at least two different subjects?
8. What are the names of students in cs1500 or cs3010?
9. What are the names of students in both cs1500 and
cs1200?
10. What are the names of all the students in cs1500?
Solution:
o code(Subject)
o name(Student)
o name, id (Student) id(code=cs3020(enrolledIn))
o code,id (enrolledIn) id (name=hector (Student))
o lecturer (code=cs1500 (Subject))
o lecturer (code=cs1500 OR code=cs3020 (Subject))
o lecturer,code (Subject) (code (Subject) code (enrolledIn))
o name,id (Student) id (code=cs3010 OR code=cs1500 (enrolledIn))
o name,id (Student) id (code=cs1200 AND code=cs1500 (enrolledIn))
o name,id (Student) id (code=cs1500 (enrolledIn))

Anda mungkin juga menyukai