th ờ i gian thi: 90 phút hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i...

15
Database System Review

Upload: grace-walters

Post on 26-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Database System Review

Page 2: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Thời gian thi: 90 phút Hình thức thi: lý thuyết (trắc nghiệm + trả lời

ngắn) + bài tập (đề mở) Cấu trúc bài thi:

◦ A. Lý thuyết tổng hợp : 2.5đ◦ B. Bài tập : 7.5đ

Thiết kế E(E)RD : 3đ Ánh xạ : 1đ Viết SQL : 1.5đ Bảo mật : 0.5đ Chuẩn hóa, tìm khóa : 1.5đ

Nội dung thi

Page 3: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions

1. Given the below database schema

Page 4: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions1. (cont.)a. Map this schema into ERD

b. Write SQL statements to: For each book that is loaned out from the "Sharpstown"

branch and whose DueDate is today, retrieve the book title, the borrower's name, and the borrower's address.

For each library branch, retrieve the branch name and the total number of books loaned out from that branch

Retrieve the names, addresses, and number of books checked out for all borrowers who have more than five books checked out

Page 5: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions

Page 6: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions Given a relation Emp, the degree of the

Emp relation is? Given a relation SalGrade, the cardinality of

the SalGrade relation is? Given a relation Emp, a relation schema of

the Emp relation is? Given a relation Emp, is it possible to

conclude that the Emp relation is in the first normal form?

Page 7: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions Given a relation Emp, which SQL statements

are used in order to insert into the Emp relation the data about a new employee whose empno is 1234, ename is Tam, job is salesman, MGR is 7698, hire date is 15/07/1996, salary is 1800, and department is sales

Page 8: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions

a. Insert into EMP values(1234, ' Tam', ' salesman ', 7698, TO_DATE(' 15/07/1996', 'DD-MM-YYYY'), 1800, NULL,30);

b. Insert into EMP values(1234, ' Tam', ' salesman ', 7698, TO_DATE(' 15/07/1996', 'DD-MM-YYYY'), 1800, NULL,(SELECT DEPNO FROM DEPT WHERE DNAME = ‘Sales”));

c. Insert into EMP (Empno, Ename, Job, MGR, HireDate, SAL, DepNo) values(1234, ' Tam', ' salesman ', 7698, TO_DATE(' 15/07/1996', 'DD-MM-YYYY'), 1800, 30);

d. All a, b, and c are correct.e. None of them is correct.

Page 9: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions Given a relation Emp, which SQL statements

are used in order to insert into the Emp relation the data about a new employee whose empno is 2345, ename is Tam, job is Manager, MGR is Null, hire date is 15/07/1996, salary is 1800, and department is human resource

Page 10: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions

a. Insert into EMP values(2345, ' Tam', ‘Manager ', NULL, TO_DATE(' 15/07/1996', 'DD-MM-YYYY'), 1800, NULL, NULL);

b. Insert into EMP values(1234, ' Tam', ' salesman ', NULL, TO_DATE(' 15/07/1996', 'DD-MM-YYYY'), 1800, NULL,(SELECT DEPNO FROM DEPT WHERE DNAME = ‘human resource”));

c. All a, b are correct.d. Both a and b are unable to be used for that

insertion because there is no data about the deparment of human resource in the Dept relation and the foreign key constraint is therefore violated.

Page 11: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Normalization

Page 12: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions

3. Consider this database with the following functional depencies (primary key is (FactoryNumber, ProductNumber) and candidate key is (FactoryName, ProductNumber))

Production (FactoryNumber, FactoryName, ProductNumber, Status, Location, QtyOnDay)

FactoryNumber FactoryName FactoryNumber Status Status Location Location Status FactoryNumber, ProductNumber QtyOnDay FactoryName, ProductNumber QtyOnDay

Page 13: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Sample questions Given database with its relation Production

as shown above, which normal form is the Production relation in?a. First normal formb. Second normal formc. Third normal formd. Boyce-Codd normal form

Can you normalize it into the highest level?

Page 14: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Consider the relation R, which has attributes that hold schedules of courses and sections at a university.

R = {CourseNo, SecNo, OfferingDept,CreditHours, CourseLevel, InstructorSSN,Semester, Year, Days_Hours, RoomNo,NoOfStudents}

Suppose that the following functional dependencies hold on R:

{CourseNo} -> {OfferingDept, CreditHours,CourseLevel} {CourseNo, SecNo, Semester, Year} ->{Days_Hours,

RoomNo, NoOfStudents,InstructorSSN} {RoomNo, Days_Hours, Semester, Year} -> {InstructorSSN,

CourseNo, SecNo}

Try to determine which sets of attributes form keys of R. How would you normalize this relation?

More exercises

Page 15: Th ờ i gian thi: 90 phút Hình th ứ c thi: lý thuy ế t (tr ắ c nghi ệ m + tr ả l ờ i ng ắ n) + bài t ậ p (đ ề m ở ) C ấ u trúc bài thi: ◦ A. Lý thuy

Consider the following relation for published books: BOOK (Book_title, Authorname, Book type

Book_type, Listprice, Author_affil,Publisher)

Author_affil referes to the affiliation of the author  Suppose the following dependencies exist: Book_title -> Publisher, Book_type Book Book_type -> Listprice Author_name -> Author-affil

Find keys and normalize this relation into 3NF

More exercises