IT Learning HubIT Learning Hub
WEEK 1 · PRACTICE EXERCISES

Exercises & Answer Key

IT004BTTH1Fitness & Sports Center

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

Fitness & Sports Center (TrungTam_TDTT)

The Week 1 exercise consists of 2 independent requirements, to be carried out in SQL Server Management Studio. Submit each requirement as a separate script file.

Assignment requirement 1 - Design and data entry

Given the "Fitness & Sports Center Management" database schema consisting of the following 6 relations:

PHONGTAP (MAPH, TENPHONG, DIACHI, SUCCHUA, TRANGTHAI)

Predicate: Stores gym room information: room code, room name, address, maximum capacity (number of people), and room status (active, under maintenance, closed…).

AttributeData typeDescription
MAPHchar(5)Gym room code - primary key
TENPHONGvarchar(50)Gym room name
DIACHIvarchar(100)Gym room address
SUCCHUAintMaximum capacity (number of people)
TRANGTHAIvarchar(20)Room status (active, under maintenance, closed…)

HUANLUYENVIEN (MAHLV, HOTEN, CHUYENMON, SDT, EMAIL)

Predicate: Stores trainer information: trainer code, full name, specialty (Yoga, Gym,...), phone number, and contact email.

AttributeData typeDescription
MAHLVchar(5)Trainer code - primary key
HOTENvarchar(50)Full name
CHUYENMONvarchar(50)Specialty (Yoga, Gym,...)
SDTvarchar(15)Phone number
EMAILvarchar(50)Contact email

HOCVIEN (MAHV, HOTEN, NGSINH, SDT, DIACHI, GIOITINH, NGTG)

Predicate: Stores member information: member code, full name, date of birth, phone number, address, gender (Male, Female), and the date the person joined as a member.

AttributeData typeDescription
MAHVchar(5)Member code - primary key
HOTENvarchar(50)Full name
NGSINHsmalldatetimeDate of birth
SDTvarchar(15)Phone number
DIACHIvarchar(100)Member address
GIOITINHvarchar(10)Member gender (Male, Female)
NGTGsmalldatetimeDate the person joined as a member

LOPTAP (MALOP, MAPH, MAHLV, TENLOP, NGAYBD, NGAYKT, TRANGTHAI)

Predicate: Stores class information: class code, room where it takes place, trainer in charge, class name, start date, end date, and class status (in progress, ended, paused…).

AttributeData typeDescription
MALOPchar(5)Class code - primary key
MAPHchar(5)Gym room code - foreign key to PHONGTAP
MAHLVchar(5)Trainer code - foreign key to HUANLUYENVIEN
TENLOPvarchar(50)Class name
NGAYBDsmalldatetimeClass start date
NGAYKTsmalldatetimeClass end date
TRANGTHAIvarchar(20)Class status (in progress, ended, paused…)

DANGKY (MAHV, MALOP, NGAYDK)

Predicate: Enrollment details: which member registered for which class, and on what date.

AttributeData typeDescription
MAHVchar(5)Member code - primary key, foreign key to HOCVIEN
MALOPchar(5)Class code - primary key, foreign key to LOPTAP
NGAYDKsmalldatetimeRegistration date

LICHTAP (MALOP, NGAYTAP, GIOBATDAU, GIOKETTHUC)

Predicate: Stores each class's schedule: the date of a session, the start time, and the end time.

AttributeData typeDescription
MALOPchar(5)Class code - primary key, foreign key to LOPTAP
NGAYTAPsmalldatetimeSession date - primary key
GIOBATDAUtimeSession start time - primary key
GIOKETTHUCtimeSession end time
Full exercise - Week 1 practice (BTTH1) PDF file · full sample data for all 6 relations
Download ↓
Submission requirement (Requirement 1): Save your work in the script file <MSSV>_<HoVaTen>_BTTH1_YC1.sql (MSSV is your student ID, HoVaTen is your full name).
  1. Create the database TrungTam_TDTT, containing the 6 relations PHONGTAP, HUANLUYENVIEN, HOCVIEN, LOPTAP, DANGKY, LICHTAP.
  2. Create the primary keys and foreign keys for the relations above.
  3. Enter data for the 6 relations using the sample data provided in the exercise file.

Assignment requirement 2 - Definition and data manipulation

From this point on, the exercise switches to the shared Sales Management schema (KHACHHANG, NHANVIEN, SANPHAM, HOADON, CTHD).

See the full attributes, sample data, and database script for the Sales Management schema before starting. View schema ›
Submission requirement (Requirement 2): Save your work in the script file <MSSV>_<HoVaTen>_BTTH1_YC2.sql (MSSV is your student ID, HoVaTen is your full name).

Part I - Data Definition Language

  1. Add an attribute GHICHU with data type varchar(20) to the relation SANPHAM.
  2. Add an attribute LOAIKH with data type tinyint to the relation KHACHHANG.
  3. Change the data type of the attribute GHICHU in the relation SANPHAM to varchar(100).
  4. Drop the attribute GHICHU in the relation SANPHAM.
  5. How can the attribute LOAIKH in the relation KHACHHANG be made to store the values "Vang lai", "Thuong xuyen", "Vip", …?
  6. A product's unit of measure can only be one of ("cay", "hop", "cai", "quyen", "chuc").
  7. A product's selling price must be 500 or higher.
  8. An employee's phone number must start with the digit "0".
  9. Each time a customer makes a purchase, they must buy at least 1 product.
  10. The date a customer registers as a member must be later than that person's date of birth.

Part II - Data Manipulation Language

  1. Create the relation SANPHAM1 containing all the data of the relation SANPHAM. Create the relation KHACHHANG1 containing all the data of the relation KHACHHANG.
  2. Update the price with a 5% increase for products manufactured in "Thai Lan" (for the relation SANPHAM1).
  3. Update the price with a 5% decrease for products manufactured in "Trung Quoc" priced at 10,000 or below (for the relation SANPHAM1).
  4. Update the LOAIKH value to "Vip" for customers who registered as members before 1/1/2007 with total sales of 10,000,000 or more, or customers who registered as members on or after 1/1/2007 with total sales of 2,000,000 or more (for the relation KHACHHANG1).

ANSWER

View answer

Protected content

Enter the access code to view the Week 1 answer.

Access code provided by the instructor.