Specify the following queries on the COMPANY relational database schema shown in Figure 3.5, using the relational operators discussed in this chapter. Also show the result of each query as it would apply to the database state in Figure 3.6.
用 Latex 打這東西真痛苦,每個文字都要用 \text{}
包住,符號也得額外查詢。
a. Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ProductX project.
b. List the names of all employees who have a dependent with the same first name as themselves.
c. Find the names of all employees who are directly supervised by ‘Franklin Wong’.
d. For each project, list the project name and the total hours per week (by all employees) spent on that project.
這題第一行的 JOIN 是 Left Outer Join,只是我真的打不出那個字了。
e. Retrieve the names of all employees who work on every project.
f. Retrieve the names of all employees who do not work on any project.
g. For each department, retrieve the department name and the average salary of all employees working in that department.
h. Retrieve the average salary of all female employees.
i. Find the names and addresses of all employees who work on at least one project located in Houston but whose department has no location in Houston.
j. List the last names of all department managers who have no dependents.
Consider the LIBRARY relational database schema shown in Figure 6.14, which is used to keep track of books, borrowers, and book loans. Referential integrity constraints are shown as directed arcs in Figure 6.14. Write down relational expressions for the following queries:
a. How many copies of the book titles The Lost Tribe are owned by the library branch whose name is ‘Sharpstown’?
b. How many copies of the book titles The Lost Tribe are owned by each library branch?
c. Retrieve the names of all borrowers who do not have any books checked out.
d. For each book that is loaned out from the Sharpstown branch and whose Due_date is today, retrieve the book title, the borrower’s name, and the borrower’s address.
我不知道要怎麼定義 today
是哪一天,因此請允許我直接用 "today"
代指應該要選的那天。
e. For each library branch, retrieve the branch name and the total number of books loaned out from that branch.
f. Retrieve the names, addresses, and number of books checked out for all borrowers who have more than five books checked out.
g. For each book authored (or coauthored) by Stephen King, retrieve the title and the number of copies owned by the library branch whose name is Central.
我不知道在這個資料庫內怎麼尋找共同作者,因此我就只尋找作者名。
Consider the following set of requirements for a UNIVERSITY database that is used to keep track of students’ transcripts. This is similar but not identical to the database shown in Figure 1.2:
a. The university keeps track of each student’s name, student number, Social Security number, current address and phone number, permanent address and phone number, birth date, sex, class (freshman, sophomore, …, graduate), major department, minor department (if any), and degree program (B.A., B.S., …, Ph.D.). Some user applications need to refer to the city, state, and ZIP Code of the student’s permanent address and to the student’s last name. Both Social Security number and student number have unique values for each student.
b. Each department is described by a name, department code, office number, office phone number, and college. Both name and code have unique values for each department.
c. Each course has a course name, description, course number, number of semester hours, level, and offering department. The value of the course number is unique for each course.
d. Each section has an instructor, semester, year, course, and section number. The section number distinguishes sections of the same course that are taught during the same semester/year; its values are 1, 2, 3, …, up to the number of sections taught during each semester.
e. A grade report has a student, section, letter grade, and numeric grade (0, 1, 2, 3, or 4).
Design an ER schema for this application, and draw an ER diagram for the schema. Specify key attributes of each entity type, and structural constraints on each relationship type. Note any unspecified requirements, and make appropriate assumptions to make the specification complete.
每個 Table 的 Key attribute 為:(我不知道怎麼在圖形內加上底線,因此文字敘述)
STUDENT
:Student_id
, Ssn
DEPARTMENT
: Department_code
SECTION
: Section_number
另外 CURRENT_ADDRESS
、 PERMANENT_ADDRESS
與 GRADE_REPORT
都屬於 weak entity ,沒畫上去是因為沒有 double diamond
以及 double box
這類型的 shape
其他沒特別提到的限制等等我在圖形內應該都表示了,我盡可能地根據題目要求作圖。
我知道圖很小(物件太多了),但我已經盡全力將圖形畫好了。
有些 edge 有 overlapping 的問題,但我不知道怎麼移動特定 edge 讓他不用穿圖。
使用的套件是 Graphviz,在Hackmd上作圖用這個還算不錯。
Consider the ER diagram shown in Figure 7.21 for part of a BANK database. Each bank can have multiple branches, and each branch can have multiple accounts and loans.
a. List the strong (nonweak) entity types in the ER diagram.
BANK
, ACCOUNT
, LOAN
, CUSTOMER
b. Is there a weak entity type? If so, give its name, partial key, and identifying relationship.
BANK_BRANCH
Branch_no
BRANCHES
c. What constraints do the partial key and the identifying relationship of the weak entity type specify in this diagram?
在具有 BANK
的 Code
與 BANK_BRANCH
的 Branch_no
情況下才能 uniquely indentify 每個銀行的分部。
d. List the names of all relationship types, and specify the (min, max) constraint on each participation of an entity type in a relationship type. Justify your choices.
BRANCHES
: BANK
的 (min, max) 為 (1, 1);BANK_BRANCH
的 (min, max) 為 (1, n)。
ACCTS
:BANK_BRANCH
的 (min, max) 為 (1, 1);ACCOUNT
的 (min, max) 為 (0, n)。
LOANS
:BANK_BRANCH
的 (min, max) 為 (1, 1);LOAN
的 (min, max) 為 (0, n)。
A_C
:ACCOUNT
的 (min, max) 為 (1, n);CUSTOMER
的 (min, max) 為 (1, n)。
L_C
:LOAN
的 (min, max) 為 (0, n);CUSTOMER
的 (min, max) 為 (1, n)。
e. List concisely the user requirements that led to this ER schema design.
這個設計是從銀行的角度看過去,一個銀行在各地有著許多分部,每個分部底下都有各自的帳戶資料及借貸資料,分別對應到不同人。
f. Suppose that every customer must have at least one account but is restricted to at most two loans at a time, and that a bank branch cannot have more than 1,000 loans. How does this show up on the (min, max) constraints?
CUSTOMER
的 (min, max) 為 (0, Infinity),而 LOAN
的 (min, max) 為 (0, 0)。CUSTOMER
的 (min, max) 為 (0, 1000),而 LOAN
的 (min, max) 為 (0, 1000)。CUSTOMER
的 (min, max) 為 (0, 500),而 LOAN
的 (min, max) 為 (0, 1000)。從以上的討論可以得出:LOAN
的 (min, max) 為 (0, 1000),但是對於 CUSTOMER
則是不明,會根據實際的借貸筆數狀況而影響實際 (min, max)。
1112_courses
database