IT Learning HubIT Learning Hub
WEEK 6 · PRACTICE EXERCISES

Exercises & Answer Key

IT004Comprehensive ReviewGoods Management

The exercise statement is open to read freely. The answer key and detailed explanations are reserved for students currently enrolled in the IT004 practicum class and require an access code from the instructor.

EXERCISE

Practice requirements - Goods Management (36 questions)

A comprehensive review exercise using the classic "Suppliers - Parts - Shipments" schema, a very common example in database courses and exams. Students complete the following 36 questions in order:

NHACUNGCAP (MANCC, TENNCC, TRANGTHAI, THANHPHO)

Predicate: A "supplier" provides shipping services - supplier code, supplier name, status, and city.

AttributeData typeDescription
MANCCvarchar(5)Supplier code - primary key
TENNCCvarchar(20)Supplier name
TRANGTHAInumeric(2)Status (supplier rating score)
THANHPHOvarchar(30)City

PHUTUNG (MAPT, TENPT, MAUSAC, KHOILUONG, THANHPHO)

Predicate: Part information: part code, part name, color, weight, and city.

AttributeData typeDescription
MAPTvarchar(5)Part code - primary key
TENPTvarchar(10)Part name
MAUSACvarchar(10)Color
KHOILUONGfloatWeight
THANHPHOvarchar(30)City

VANCHUYEN (MANCC, MAPT, SOLUONG)

Predicate: Records which supplier shipped which part, and in what quantity.

AttributeData typeDescription
MANCCvarchar(5)Supplier code - primary key, foreign key to NHACUNGCAP
MAPTvarchar(5)Part code - primary key, foreign key to PHUTUNG
SOLUONGnumeric(5)Quantity of parts shipped

Relationship diagram

NHACUNGCAP VANCHUYEN PHUTUNG

NHACUNGCAP (1) ➜ VANCHUYEN (N): a supplier can ship many different part rows.

PHUTUNG (1) ➜ VANCHUYEN (N): a part can be shipped by many suppliers.

Goods Management database script (PartShipmentDB) .sql file · full table creation, constraints, and sample data
Download ↓
  1. Display the (MANCC, TENNCC, THANHPHO) information for all suppliers.
  2. Display the information for all parts.
  3. Display the information for suppliers located in London.
  4. Display the part code, name, and color for all parts located in Paris.
  5. Display the part code, name, and weight for parts with a weight greater than 15.
  6. Find parts (MAPT, TENPT, MAUSAC) with a weight greater than 15 that are not red.
  7. Find parts (MAPT, TENPT, MAUSAC) with a weight greater than 15 whose color is neither red nor green.
  8. Display parts (MAPT, TENPT, weight) with a weight greater than 15 and less than 20, sorted by part name.
  9. Display the parts shipped by supplier S1, with no duplicate rows (use a join).
  10. Display the suppliers that shipped part P1 (use a join).
  11. Display information for suppliers located in London that shipped parts located in London, with no duplicate rows (use a join).
  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 using a subquery with the IN operator.
  17. Repeat question 11 using a subquery with the EXISTS operator.
  18. Find suppliers that have not shipped any part yet. Use NOT IN.
  19. Find suppliers that have not shipped any part yet. Use NOT EXISTS.
  20. Find suppliers that have not shipped any part yet. Use an outer JOIN.
  21. How many suppliers are there in total?
  22. How many suppliers are there in London?
  23. Display the highest and lowest TRANGTHAI value among all suppliers.
  24. Display the highest and lowest TRANGTHAI value in the NHACUNGCAP table for suppliers in London.
  25. How many parts did each supplier ship? Show only the supplier code and total quantity shipped.
  26. How many parts did each supplier ship? Show the supplier code, name, city, and total quantity shipped.
  27. Which suppliers shipped a total of more than 500 parts? Show only the supplier code.
  28. Which suppliers shipped more than 300 red parts? Show only the supplier code.
  29. Which suppliers shipped more than 300 red parts? Show the supplier code, name, city, and quantity of red parts shipped.
  30. How many suppliers are there in each city?
  31. Which supplier shipped the most parts? Show the supplier name and quantity of parts shipped.
  32. Which cities have both a supplier and a part.
  33. Write the SQL statement to insert a new supplier: S6, Duncan, 30, Paris.
  34. Write the SQL statement to change S6's city (from question 33) to Sydney.
  35. Write the SQL statement to increase TRANGTHAI by 10 for suppliers in London.
  36. Write the SQL statement to delete supplier S6.

ANSWER

View answer

Protected content

Enter the access code to view the Week 6 answer.

Access code provided by the instructor.