Upload
jdphan
View
18
Download
0
Embed Size (px)
DESCRIPTION
Exercise
Citation preview
1
CXCP 216 Intro to SQL Instructor: Mohamed Khan
FINAL EXERCISE SET -4 Worth 20 Marks Two Parts A & B
PART A: Refer to text( worth 4 marks)Chaper 8: Questions 1, 2Chapter 9: 1 and 2Chapter 10: 1, 2, 3, 4 ======================================================Part B :( worth 10 marks) Refer to Chapter 11. Create the Library database given on your recent Mid-Term TestLibrary Database: -- First hand-sketch this database diagram and once it has been DDL-created generate the diagram. PKs are highlighted and FKs are shown in parentheses. You will need to come up with your own data.AUTHORAu-BkBOOKBOOKCOPYLOANLOANDETAILSPUBLISHERMEMBER
AuthorID(AuthorIDISBN-NoCallNumLoanID*(LoanID+PublisherIDMemberID
ALNameISBN-No)BookTitle(MemberID)CallNum)PublisherNameMLName
AFName(AuthorID)(ISBN-No)LoanDateDueDateMFName
CopiesCondition ReturnDateAddress
(PublisherID)StatusStatus
Note: AuthorID and ISBN-No are also foreign keysNote: LoanID and CallNum are also Foreign KeysMembership Date
Generate PK start at 10 with increments of 5Generate PK Start at 1000 with increments of 1Assign PK Start with CN1, CN2 etcGenerate PK Start with 100 with increments of 1 Composite( LoanID + CallNo)Generate PKStart with 1 and increment by 1Generate PKStart with 10000 and increment by 100
1:M with Au-BkSee Author and Book1:M with Au-Bk1: 0 or 1 with LOANDETAILS
1:M with LOANDETAILS
See Bookcopy1:M with BOOK
1:M with LOAN
Insert 5 records
Insert 10 recordsInsert 10 records
Insert 15 records
Insert 5 records
Insert 15 records
Insert 5 records
Insert 5 records
a. Required : Use SQL DDL statements to create the library database ( LibraryDB). Assume Null and Non-Null fields. Set any Default values and constraints. Create at least 8 indexes. Generate the database diagram.
b.
(i) Write a SELECT statement that returns THREE columns that show the author by Lastname, FirstName,. Group and Count number of titles for a given author. Order appropriately.
(ii) Write a SELECT Statement that groups Members and their Loans and LoanDetails ( show also the titles that they have borrowed)
(iii) Make up your own Query question ( different from (i) & (ii) ) with joins of 3 or more tables code and show the results.
c. Generate the database diagram2