0% found this document useful (0 votes)
16 views4 pages

Lab 3

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)
16 views4 pages

Lab 3

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
You are on page 1/ 4

Exercise 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:

CLASS(ClassCode, ClassName, Size)

Definition: Each class has a unique class code (ClassCode), a class name (ClassName), and a
corresponding class size (Size). Constraint: Size > 0.

SUBJECT (SubjectCode, SubjectName, TheoryCredits, PracticeCredits)

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.

STUDENT(StudentID, FullName, DateOfBirth, Gender, ClassCode)

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.

SCORE_STUDENT(StudentID, SubjectCode, Score)

Definition: Student performance is stored in the SCORE_STUDENT table. Constraint: Score can be
NULL or 0 ≤ Score <= 10.

Description:

Attribute Data type

ClassCode char(6)

ClassName nvarchar(50)

Size tinyint

SubjectCode char(5)

SubjectName nvarchar(50)

TheoryCredits, PracticeCredits tinyint

StudentID char(5)

FullName nvarchar(50)

DateOfBirth date

Gender bit

Score decimal(3,1)
I. Prepare Data:
CLASS:

ClassCode ClassName Size

18DTH01 CNTT Khóa 18, Lớp 1 50

18DTH02 CNTT Khóa 18, Lớp 2 45

19DTH01 CNTT Khóa 19, Lớp 1 55

19DTH02 CNTT Khóa 19, Lớp 2 50

19DTH03 CNTT Khóa 19, Lớp 3 40

SUBJECT:

SubjectCode SubjectName TheoryCredits PracticeCredits

COS201 Kỹ thuật lập trình 2 1

COS202 Lý thuyết đồ thị 2 1

COS203 CSDLvà quản trị CSDL 3 0

COS204 Phân tích thiết kế hệ thống 3 0

COS205 CSDL phân tán 3 0

STUDENT:

Studen
FullName DateOfBirth Gender MaLop
tID

170001 Lê Hoài An 12/10/1999 0 18DTH01

180002 Nguyễn Thị Hòa Bình 20/11/2000 0 18DTH01

180003 Phạm Tường Châu 07/06/2000 1 18DTH02

180004 Trần Công Danh 31/01/2000 1 19DTH01

SCORE_STUDENT

MSSV MaMH Diem

170001 COS201 10

170001 COS202 10

170001 COS203 10
170001 COS204 10

170001 COS205 10

180002 COS201 3.5

180002 COS202 7

180003 COS201 8.5

180003 COS202 2

180003 COS203 6.5

180004 COS201 8

180004 COS204 NULL

II. Execute the Query:

1. Insert a new record into STUDENT table:

190001 Đào Thị Tuyết Hoa 08/03/2001 0 19DTH02

2. Rename the subject Lý thuyết đồ thị ' to Toán rời rạc '.

3. Display the names of the subjects without practice sessions.

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.

14. List the names of students and their average 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.

29. Delete all students who haven't taken any exams.

30. Display the subjects that all students have registered for.

You might also like