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

Assignment 1

IT001 Assignment

Uploaded by

tuanvip870
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)
79 views3 pages

Assignment 1

IT001 Assignment

Uploaded by

tuanvip870
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

Assignment 1 – SQL (Parts Database)

The Suppliers and Parts Database

All questions in this lab/tutorial relate to the Parts database, shown below. The Parts Database is
used by C.J. Date in his database textbooks and articles. C.J. Date is one of the most respected
thinkers in relational database theory, and his database is commonly used in database teaching
and exercises.

Supplier (SNO, SName, Status, City)


Description: Information about suppliers who provide parts. Each supplier has a unique
identifying supply number (SNO), a name (SName), and a city location (City).

Part (PNO, PName, Color, Weight, City)


Description: Details about the parts. Each part has a unique identifying part number (PNO), a
name (PName), color (Color), and weight (Weight) and is stored in a city (City).

Project (JNO, JName, City)


Description: information about projects that would use parts. Each project has a unique
identifying project number (JNO) and a project name (JName) and is located in a city (City).

Shipment (SNO, PNO, Qty):


Description: Records of which suppliers ship which parts, including quantities. SNO refers to
the supplier's identifying number. PNO refers to the part number of the shipped part, and Qty is
the quantity of part of each shipment.

Shipment_for_Project (SNO, PNO, JNO, Qty)


Description: showing which shipments (from the Shipment table) are assigned to which
projects. SNO refers to the supplier number, PNO refers to the part number, and JNO is the
project number. Qty is the quantity of parts from a specific shipment allocated to a project.

Sample data for the Supplier, Part, and Shipment tables:


Supplier
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Part
P1 Nut Red 12.0 London
P2 Bolt Green 17.0 Paris
P3 Screw Blue 17.0 Oslo
P4 Screw Red 14.0 London
P5 Cam Blue 12.0 Paris
P6 Cog Red 19.0 London
Shipment
S1 P1 300
S1 P2 200
S1 P3 400
S1 P4 200
S1 P5 100
S1 P6 100
S2 P1 300
S2 P2 400
S3 P2 200
S4 P2 200
S4 P4 300
S4 P5 400

Questions
I. Data Definition Language
1. Write SQL create table statements for all tables of the database.
2. Alter the shipments table and add a constraint that the QTY value must be greater than 0.
3. Write an SQL statement to implement the following constraint: the part named "Bolt" is only
stored in Paris.
II. Data Manipulation Language
1. Write SQL statements to insert given sample data into 03 tables: Supplier, Part, and
Shipment.
2. Write an SQL statement to insert a new supplier: S6, Duncan, 30, Paris.
3. Write an SQL statement to change S6’s city to Sydney.
4. Write an SQL statement to increase each London supplier’s status by 10.
5. Write an SQL statement to delete supplier S6.
III. Data Query Language
1. Show full details of all suppliers.
2. Show full details of all parts.
3. Show full details of all suppliers in London.
4. Show the part number (PNO), name and color of all parts located in Paris.
5. Show the part number and name of all parts that weigh more than 15.
6. Show the part number and name of all parts that weigh more than 15 and are not red.
7. Show the part number and name of all parts that weigh more than 15 and are neither red nor
green.
8. Show the part number and name of all parts that weigh between 15 and 19 inclusive. Order
the results by part name.
9. Show full details of all parts that have been shipped by supplier S1. Use a join query and
make sure no duplicates appear in your output. (Note: it is recommended that you try both
implicit and explicit joins.)
10. Show full details of suppliers who have shipped the part P1. Use a join query and make sure
no duplicates appear in your output.
11. Show full details of suppliers who are located in London and have shipped parts that are
located in London. Use a join query and make sure no duplicates appear in your output.
12. Repeat question 9 but use the IN operator.
13. Repeat question 10 but use the IN operator.
14. Repeat question 9 but use the EXISTS operator.
15. Repeat question 10 but use the EXISTS operator.
16. Repeat question 11 but use a subquery inside a subquery. Use the IN operator.
17. Repeat question 11 but use a subquery inside a subquery. Use the EXISTS operator.
18. Show details of suppliers who have never made a shipment. Use the NOT IN operator.
19. Show details of suppliers who have never made a shipment. Use the NOT EXISTS operator.
20. Show details of suppliers who have never made a shipment. Use an outer JOIN.
21. How many suppliers are there?
22. How many suppliers are there in London?
23. Show the maximum and minimum status values in the supplier table.
24. Show the maximum and minimum status values in the supplier table for London suppliers.
25. How many parts has each supplier shipped? Show the supplier number (SNO) total shipped
only.
26. How many parts has each supplier shipped? Show the supplier number, name and city as well
as the total shipped. (Note: you will have to modify your group by statement. Why?)
27. Which suppliers have shipped more than 500 parts in total? Show the supplier number only.
28. Which suppliers have shipped more than 300 red parts? Show the supplier number only.
29. Which suppliers have shipped more than 300 red parts? Show the supplier number, name,
and city and the number of red parts shipped. (Note: you will have to modify your group by
statement. Why?)
30. How many suppliers are there in each city?
31. Which supplier has shipped the most parts? Show the name and number.
32. Show a list of cities that have either suppliers or parts. In other words, show all the cities
from the supplier table and all the cities from the parts table. Show the results in a single
column and remove duplicates.

You might also like