0% found this document useful (0 votes)
44 views

DBMS Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

DBMS Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Base Management System Assignment-2

1. In the context of a relational model, discuss each of the following concepts.


2. Relation (b) Attributes (c) Tuple (d) Cardinality (e) Domain
3. Discuss the various types of keys that are used in relational model.
4. What do you mean by relational algebra? Define all the operators of relational algebra.
5. What do you mean by structure of relational model of database system? Explain the significance
6. of domain in the relational model.
7. What do you mean by relational calculus? What are the types of relational calculus?
8. What is difference between INNER JOIN & OUTER JOIN?
9. Describe the types of joins operation.
10. Write short notes on the following:
(i) Data Manipulation Language (DML).
(ii) Data Definition Language (DDL).
(iii) Transaction Control Statement (TCS).
(iv) Data Control Language (DCL).
11. Write a short-notes on subqueries and aggregate functions.

Problem Based on SQL Query and Relational Algebra.

1. Consider the following schema:


Suppliers(sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
The Catalog relation lists the prices charged for parts by Suppliers.

Write the following relational algebra queries in SQL:


a. Find the names of suppliers who supply some red part.
b. Find the sids of suppliers who supply some red or green part.
c. Find the sids of suppliers who supply some red part or are at 221
Packet Street.
d. Find the sids of suppliers who supply some red part and some
green part.
e. Find the sids of suppliers who supply every red part.
f. Find the sids of suppliers who supply every red or green part.
g. Find the sids of suppliers who supply every red part or supply
every green part.
h. Find paris of sids such that the supplier with the first sid charges
more for some part than the supplier with the second sid.
i. Find the pids of parts supplied by at least two different suppliers.

2. Consider the following table named Student in a relational


database. The primary key of this table is roll number.

Roll Name Gender Marks


number
1 Naman M 62
2 Aliya F 70
3 Aliya F 80
4 James M 82
5 Swati F 65

The SQL query below is executed on this database.


SELECT *
FROM Student
WHERE gender = ‘F’ AND marks > 65;
The number of rows returned by the query is?

3. Consider the following relational query on the above data base.


employee(employee-name, street, city, dob)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)
For the given relation schema, give an expression in SQL for each of the following queries:
(i) Find the names of employees who live in the same cities as the companies for which they
work.
(ii) Find the average salary of employees in a company named 'wipro'.
(iii) Find the names of managers whose employee name contains 'esh'.

4. Consider the following relations with underlined primary keys.


Product(P_code, Description, Stocking_date, QtyonHand, MinQty, Price, Discount, V_code)
Vendor (V_code, Name, Address, Phone) Write
SQL statement of following queries.
(1) List the names of all the vendors who supply more than two products.
(2) List the details of the products whose prices exceeds the average product price.
(3) List the Name, Address and Phone of the vendors who are currently not supplying any product.
(4) List the name and phone no. of supplier who supply all the products.

5. Consider the following COMPANY


database.
EMP(Name,SSN,Salary,SuperSSN,Dno)
DEPT(DNum,Dname,MgrSSN,Dno)
DEPT_LOC(Dnum,Dlocation)
DEPENDENT(ESSN,Dep_name,Sex)
WORKS_ON(ESSN,Pno,Hours)
PROJECT(Pname,Pnumber,Plocation,Dnum)

Write the SQL queries for the following


(i) Retrieve the name of the employee who works with same department as ravi
(ii)Retrieve the number of dependents for an employee “Ravi”
(i) Retrieve the name of the managers working in location “DELHI” who has no female dependents
(ii) List female employees from Dno=20 earning more than 50000
(iii) List “CSE” department details.

6. Consider the following COMPANY


database.
EMP(Name,SSN,Salary,SuperSSN,Dno)
DEPT(DNum,Dname,MgrSSN,Dno)
DEPT_LOC(Dnum,Dlocation)
DEPENDENT(ESSN,Dep_name,Sex)
WORKS_ON(ESSN,Pno,Hours)
PROJECT(Pname,Pnumber,Plocation,Dnum)

Write the SQL queries for the following


(i) Retrieve the name of the employee who works with same department as ravi
(ii)Retrieve the number of dependents for an employee “Ravi”
(iv) Retrieve the name of the managers working in location “DELHI” who has no female dependents
(v) List female employees from Dno=20 earning more than 50000
(vi) List “CSE” department details.

7. Consider the following COMPANY database


EMP(Name,SSN,Salary,SuperSSN,Gender,Dno)
DEPT(DNum,Dname,MgrSSN,Dno)
DEPT_LOC(Dnum,Dlocation)
DEPENDENT(ESSN,Dep_name,Sex)
WORKS_ON(ESSN,Pno,Hours)
PROJECT(Pname,Pnumber,Plocation,Dnum)

Write the relational algebra queries for the following:


(i) Retrieve the name, address, salary of employees who work for the Research department.
(ii) Find the names of employees who work on all projects controlled by department number 4.
(iii) Retrieve the SSN of all employees who either in department no is 4 or directly supervise an
employee who work in department number is 4
(iv) Retrieve the names of employees who have no dependents
(v) Retrieve each department number, the number of employees in the department and their average
salary.
8. Consider the following schema for institute library:
Student (RollNo, Name, Father_ Name, Branch) Book (ISBN, Title, Author, Publisher) Issue
(RollNo, ISBN, Date-of –Issue)

Write the following queries in SQL and relational algebra:


(1) List roll number and name of all students of the branch ‘CSE’.
(2) Find the name of student who has issued a book published by ‘ABC’ publisher.
(3) List title of all books and their authors issued to a student ‘RAM’.
(4) List title of all books issued on or before December 1, 2020.
(5) List all books published by publisher ‘ABC’.

9. Given the relation schema:


ENROLL (S#, C#,Section), TEACH (Prof , C#,Section), ADVICE (Prof, S#) PRE-REQ (C#, Pre-
C#) GRADE(S#, C#, grade, year) STUDENT (S#,Sname), S# is student number, C# is course
number, Prof is Thesis advisor of S#,
Pre-C# is prerequisite course. S_name is student name.
Give the queries expressed in SQL and tuple calculus.

(1) List of students taking courses with smith or jones.


(2) List all student taking at least one course that their advisor teaches.
(3) List those Professor who teaches more than one section of the same course.
(4) List all the students number and course number.
(5) List the student number and course number who got grade A.

10. Consider the employee database of Figure 2.17. Give an expression in the relational algebra to
express each of the following queries: branch(branch name, bran h city, assets) Customer
(ID, customer name, customer street, customer city) loan (loan number, bran h name,
amount) borrower (ID, loan number) amount (amount number, bran h name, balance)
depositor (ID, amount number)

a. Find the name of each employee who lives in city “Miami”.


b. Find the name of each employee whose salary is greater than $100000.
c. Find the name of each employee who lives in Miami and whose salary is greater than $100000.
d. Find the name of each bran h located in Chicago.
e. Find the ID of each borrower who has a loan in bran h Downtown.

11. Consider the following schema:


Suppliers ( sid: integer, sname: string, address: string)
Parts (pid: integer, pname: string, color: string)
Catalog ( sid: integer, pid: integer, cost: real).

The key fields are underlined, and the domain of each field is listed after the field name. Therefore sid is
the key for Suppliers, pid is the key for Parts, and sid and pid together formthe key for Catalog. The
Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in relational
algebra.

a. Find the Supplier names of the suppliers who supply a red part that costs less than 100
b. dollars.
c. Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars
and a green part that costs less than 100 dollars.
d. Find the Supplier sid of the suppliers who supply a red part that costs less than 100 dollars
and a green part that costs less than 100 dollars.
e. Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars
and a green part that costs less than 100 dollars.

12. For the following relation schema: Give an expression in SQL for each of the following queries:
employee (employee-name, street, city), works (employee-name, companyname, salary), company
(company-name, city), manages (employee-name, managername)
a) Find the names, street address, and cities of residence for all employees who work for 'First Bank
Corporation' and earn more than $10,000
b) Find the names of all employees in the database who live in the same cities as the companies for which
they work
c) Find the names of all employees in the database who live in the same cities and on the same streets as
do their managers.

13. Consider the following relational database.


Give an expression in the relational algebra to express each of the following queries: employee (person
name, street, city), works (person name, company name, salary), company (company name, city)
a) Find the names of all employees who work for "First Bank Corporation".
b) Find the names and cities of residence of all employees who work for "First Bank Corporation".
c) Find the names, street address, and cities of residence of all employees who work for "First Bank
Corporation" and earn more than $10,000.
d) Find the names of all employees in this database who live in the same city as the company for which
they work
e) Find the names of all employees who live in the same city and on the same street as do their managers.

14. Consider the following relational schema.


The following relations keep track airline
flight information:-
Flights (flno: integer, from: string, to :
string, distance: integer,
departs : time, arrives : time, price : real)
Aircraft (aid: integer, aname : string,
cruisingrange : integer)
Certified (eid : integer, aid: integer)
Employe~s (eid : integer, enarne : string,
salary: integer)

Write the relational algebra queries for


the given schema.
a. For each pilot who is certified for more than three aircraft, fmd the eid and the maximum cruisingrange of
the aircraft for which she or he is certified.
b. Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to
Honolulu.
c. Find the names of pilots certified for some Being aircraft.
d. Find the aids of all aircraft that can be used on routes from Los Angles to Chicago.

15. Consider the following relations:


Employees(emp_id: integer, emp_name: string, dept_id: integer, salary: real)
Departments(dept_id: integer, dept_name: string)
Write an SQL query to answer the following questions:
a. Find the maximum salary in each department.
b. Find the maximum salary in each department.
c. Find the average salary of employees in each department that has more than 5 employees.
d. Find the total number of employees in all departments where the average salary is greater than 50,000.
e. Find the names of departments where no employee earns a salary higher than 70,000.

You might also like