BOOK
中的一個 tuple
時
BOOK_AUTHOR
、BOOK_COPIES
、BOOK_LOANS
都需要進行 cascade
(同時刪除這本書的資料)BOOK
中的 Book_id
時
BOOK_AUTHOR
、BOOK_COPIES
、BOOK_LOANS
都需要進行 cascade
(同時修改這本書的 ID
)PUBLISHER
中的一個 tuple
時
BOOK
需要進行 set to NULL
(這本書暫時變成沒有出版商,之後再進行設定)PUBLISHER
中的 Name
時
BOOK
需要進行 cascade
(跟著修改這本書的出版商名稱)LIBRARY_BRANCH
中的一個 tuple
時
BOOK_COPIES
、BOOK_LOANS
需要進行 set to default
(我是認為書不進行分類跟放一個預設值分類本質上相同,但由於 BOOK_COPIES
中的 Branch_id
屬於 Key
,只能設為某個預設值)LIBRARY_BRANCH
中的 Branch_id
時
BOOK_COPIES
、BOOK_LOANS
都需要進行 cascade
(跟著修改這本書的分類)BORROWER
中的一個 tuple
時
BOOK_LOANS
需要進行 cascade
(還書了自然可以清理掉借書紀錄,另一種解法可能是新增一個還書日期的註記)BORROWER
中的 Card_no
時
BOOK_LOANS
需要進行 cascade
(跟著更新借書人的圖書證號)我把全部的程式碼放在同一個 Cell
裡面排版會出現問題,因此將每個部份獨立出來。
a. Retrieve the names of all senior students majoring in ‘CS’ (computer science).
Name
FROM STUDENT
WHERE Major='CS'
and class = '4'
b. Retrieve the names of all courses taught by Professor King in 2007 and 2008.
COURSE.Course_Name
COURSE
, SECTION
SECTION.Course_number=COURSE.Course_number
and SECTION.Year>='07'
and SECTION.Year<='08'
and SECTION.Instructor='King'
c. For each section taught by Professor King, retrieve the course number, semester, year, and number of students who took the section.
SECTION.Course_number
, SECTION.Semester
, SECTION.Year
, COUNT(GRADE_REPORT.Section_identifier)
SECTION
, GRADE_REPORT
GRADE_REPORT.Section_identifier=SECTION.Section_identifier
and SECTION.Instructor='King'
d. Retrieve the name and transcript of each senior student (Class = 4) majoring in CS. A transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student.
STUDENT.Name
, COURSE.Course_name
, COURSE.Course_number
, COURSE.Credit_hours
, SECTION.Semester
, SECTION.Year
, GRADE_REPORT.Grade
STUDENT
, COURSE
, SECTION
, GRADE_REPORT
STUDENT.Student_number=GRADE_REPORT.Student_number
and GRADE_REPORT.Section_identifier=SECTION.Section_identifier
and SECTION.Course_number=COURSE.Course_number
and STUDENT.class='4'
and STUDENT.Major='CS'
a. Insert a new student, <‘Johnson’, 25, 1, ‘Math’>, in the database.
b. Change the class of student ‘Smith’ to 2.
c. Insert a new course, <‘Knowledge Engineering’, ‘CS4390’, 3, ‘CS’>
d. Delete the record for the student whose name is ‘Smith’ and whose student number is 17.
我其實不理解為何會有 ’ 和 ' 這兩種符號,我不確定 SQL 到底是吃哪一種符號才對,又或者兩種符號都接受。
我在 4.12 題使用的都是 ' 的符號, 4.13 題使用的都是 ’ 符號。
從我的編輯器看得出差異,但是顯示成文字後就完全看不出差異了。
1112_courses
database