Sid and Pid Together Form The Key For Catalog. The Catalog Relation Lists The

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Q1 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 form the key for Catalog. The Catalog relation lists the
prices charged for parts by Suppliers. Write the following queries in
relational algebra and SQL.

1. Find the names of suppliers who supply some red part.


2. Find the sids of suppliers who supply some red or green part.
3. Find the sids of suppliers who supply some red part and some green part.
4. Find the pids of parts supplied by at least two different suppliers.
5. Find the pids of the most expensive parts supplied by suppliers named
Yosemite Sham.
6. Find the pids of parts supplied by every supplier at less than $200. (If any
supplier either does not supply the part or charges more than $200 for it, the
part is not selected.)

Q2 With respect to the above given schema-What does the following queries
compute?
1. πsname(πsid((σcolor=’red’Parts) (σcost<100Catalog))
Suppliers)

2. πsname(πsid((σcolor=’red’Parts) (σcost<100Catalog)
Suppliers))

3. (πsname((σcolor=’red’Parts) (σcost<100Catalog) Suppliers)) ∩


(πsname((σcolor=’green’Parts) (σcost<100Catalog) Suppliers))

4. (πsid((σcolor=’red’Parts) (σcost<100Catalog) Suppliers)) ∩


(πsid((σcolor=’green’Parts) (σcost<100Catalog) Suppliers))
5. πsname((πsid,sname((σcolor=’red’Parts) (σcost<100Catalog)
Suppliers)) ∩
(πsid,sname((σcolor=’green’Parts) (σcost<100Catalog)
Suppliers)))

Q3 Consider the following relations containing airline flight information:

Flights(flno: integer, from: string, to: string,


distance: integer, departs: time, arrives: time)
Aircraft(aid: integer, aname: string, cruisingrange: integer)
Certified(eid: integer, aid: integer)
Employees(eid: integer, ename: string, salary: integer)

Note that the Employees relation describes pilots and other kinds of employees as
well;every pilot is certified for some aircraft (otherwise, he or she would not
qualify as apilot), and only pilots are certified to fly.
Write the following queries in SQL

1. Find the eids of pilots certified for some Boeing aircraft.


2. Find the names of pilots certified for some Boeing aircraft.
3. Find the aids of all aircraft that can be used on non-stop flights from Bonn to
Madras.
4. Identify the flights that can be piloted by every pilot whose salary is more than
$100,000.
5. Find the names of pilots who can operate planes with a range greater than 3,000
miles but are not certified on any Boeing aircraft.
6. Find the eids of employees who make the highest salary.
7. Find the eids of employees who make the second highest salary.
8. Find the eids of employees who are certified for exactly three aircraft .Compute
without using COUNT (Bonus).

Q4. Consider the following relational schema. An employee can work in more than
one department; the pct_time filed of the Works relation shows the percentage of
time that a given employee works in a given department.

Emp(eid: integer, ename: string, age: integer, salary: real)


Works(eid: integer, did: integer, pct_time: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer)

Write the following queries in SQL:

a. Print the names and ages of each employee who works in both the Hardware
department and the Software department.

b. Print the name of each employee whose salary exceeds the budget of all of the
departments that he or she works in.

c. Find the managerids of managers who manage only departments with budgets
greater than $1 million.

Q5
A recording studio needs help designing its database. The studio stores information
about musicians and albums. Draw an ER diagram describing the studio’s database
for the scenario described as:
a) Each musician who records at the studio has a social security number (ssn)
and a name, and no two musicians have the same ssn. Musicians form bands.
A band is described by a unique name and has at least one musician as a
member.
b) Bands record albums, which have a title and a year of production. Each
album is recorded by exactly one band, and no two albums have the same
title and the same production year. Each album is produced by exactly one
musician. (So not to consider here that musician is a member of the
recording band.)
c) Albums are made up of songs, described by their titles. You may assume
that, if the studio no longer wants to store information about an album, then
it also does not store the songs belonging to that album. Naturally, each song
belongs to exactly one album, and all songs on the same album have
different titles

Submission instructions

(Except Q2 & Q5)Run each of your query on mysql commandline i.e


You need to create the database, schema and tables mentioned.
Float sample data values. Paste your screenshots in a single pdf file
showing your query and results.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy