Lab 3
Lab 3
Create a database that includes the following types of relationships, with underlined attributes being
the primary key and dashed underline being the foreign key:
Definition: Each class has a unique class code (ClassCode), a class name (ClassName), and a
corresponding class size (Size). Constraint: Size > 0.
Definition: Each subject has a unique subject code (SubjectCode), a subject name (SubjectName),
along with corresponding theory credits (TheoryCredits) and practice credits (PracticeCredits).
Constraint: TheoryCredits > 0, PracticeCredits ≥ 0.
Definition: Each student is distinguished by a unique student ID (StudentID), has a full name
(FullName), a date of birth (DateOfBirth), gender (Gender), and indicates which class the student
belongs to (ClassCode). Constraint: Gender has a value of 1 (Male), 0 (Female), default is 1.
Definition: Student performance is stored in the SCORE_STUDENT table. Constraint: Score can be
NULL or 0 ≤ Score <= 10.
Description:
ClassCode char(6)
ClassName nvarchar(50)
Size tinyint
SubjectCode char(5)
SubjectName nvarchar(50)
StudentID char(5)
FullName nvarchar(50)
DateOfBirth date
Gender bit
Score decimal(3,1)
I. Prepare Data:
CLASS:
SUBJECT:
STUDENT:
Studen
FullName DateOfBirth Gender MaLop
tID
SCORE_STUDENT
170001 COS201 10
170001 COS202 10
170001 COS203 10
170001 COS204 10
170001 COS205 10
180002 COS202 7
180003 COS202 2
180004 COS201 8
2. Rename the subject Lý thuyết đồ thị ' to Toán rời rạc '.
4. Display the names of the subjects that have both theory and practice sessions.
5. Print the names of the subjects whose names start with the letter 'C'.
6. List the information of students whose last name contains the word 'Thị'.
7. Print the top 2 classes with the largest number of students (in various ways). Display: Class Code,
Class Name, Class Size. Comments?
8. Print the list of students by each class: Student ID, Full Name, Date of Birth, Gender (Male/Female).
9. List students who are 20 years old or older, including information: Student's Full Name, Date of
Birth, Age.
10. List the names of the subjects students have taken but do not have a score yet.
11. List the academic results of the student with ID number 170001. Display: Student ID, Full Name,
Subject Name, Score.
12. List the student names and the subject codes for which they registered with scores above 7.
13. List the names of subjects along with the number of students who have taken and received
scores.
15. List the names of students with the highest score in the subject 'Programming Techniques'.
16. List the name of the student with the highest average score.
17. List the names of students who have not taken the subject 'Discrete Mathematics'.
18. List the students who were born in the same year as the student named 'Danh'.
19. Display the total number of students and the total number of female students.
20. Display the list of students who failed at least one subject.
21. Display the Student ID and Full Name of students who have taken and received scores in at least
3 subjects.
22. Print the list of students with the highest score in the subject 'Programming Techniques' for each
class.
23. Print the list of students with the highest score in each subject, by class.
24. Display the students with the highest score in each subject.
25. Display the Student ID and Full Name of students who haven't registered for any subject.
26. List the students who have a perfect score of 10 in all subjects.
27. Count the number of male and female students in each class.
28. Display the students who have taken all subjects without failing any.
30. Display the subjects that all students have registered for.