0% found this document useful (0 votes)
5 views3 pages

01 ct01

The document contains solutions to a class test on Database Management Systems, focusing on E-R diagrams, relational algebra, and SQL queries. It includes tasks related to a car insurance company, an employee database, and a library database, with specific queries and answers provided. The solutions demonstrate the application of database concepts and query languages in practical scenarios.

Uploaded by

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

01 ct01

The document contains solutions to a class test on Database Management Systems, focusing on E-R diagrams, relational algebra, and SQL queries. It includes tasks related to a car insurance company, an employee database, and a library database, with specific queries and answers provided. The solutions demonstrate the application of database concepts and query languages in practical scenarios.

Uploaded by

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

Indian Institute of Technology, Kharagpur

Department of Computer Science and Engineering


CS30202 : Database Management Systems (DBMS)
Class Test - 1 (Solution)

1. Construct an E-R diagram for a car insurance company whose customers own one or more cars
each. Each car has associated with it zero to any number of recorded accidents. Each insurance
policy covers one or more cars and has one or more premium payments associated with it. Each
payment is for a particular period of time, and has an associated due date, and the date when the
payment was received. (8 Marks)

Answer
2. Consider the employee database shown below. Give an expression in the relational algebra to
express each of the following queries: (4 Marks)

Employee Database
employee (id, name, street, city)
works (id, company name, salary)
company (company name, city)

(i) Find the ID and name of each employee who works for “BigBank”.

Answer

(ii) Find the ID and name of each employee in this database who lives in the same
city as the company for which she or he works.

Answer

3. Consider the library database shown below. Write the following queries in SQL. (8 Marks)

Library Database
member(memb_no, name)
book(isbn, title, authors, publisher)
borrowed(memb_no, isbn, date)

(i) Find the member number and name of each member who has borrowed at least one book
published by “McGraw-Hill”.

Answer

SELECT
memb_no, name
FROM
member AS m
WHERE EXISTS (
SELECT *
FROM
book
INNER JOIN
borrowed
ON
book.isbn = borrowed.isbn
WHERE
book.publisher = 'McGraw-Hill' AND borrowed.memb_no = m.memb_no
)

(ii) For each publisher, find the member number and name of each member who has borrowed more
than five books.

Answer

WITH
member_borrowed_book(memb_no, memb_name,isbn,title,authors,publisher,date)
AS (
SELECT
member.memb_no, name, book.isbn, title, authors, publisher, date
FROM
member INNER JOIN borrowed ON member.memb_no = borrowed.memb_no
INNER JOIN
book
ON
borrowed.isbn = book.isbn
)
SELECT
memb_no, memb_name, publisher, COUNT(isbn)
FROM
member_borrowed_book
GROUP BY
memb_no, memb_name, publisher
HAVING COUNT(isbn) > 5;

You might also like