Download presentation
Presentation is loading. Please wait.
Published bySarah Peggs Modified over 10 years ago
1
By Helen Spiropoulos
2
This database models the UTS Library Website: www.lib.uts.edu.auwww.lib.uts.edu.au It allows users to search for resources (book, journal, dvd, cd etc) by subject, author, title, category and publisher. Staff can check if students have loans overdue and also when student cards expire. They can also access the sales contact of publishers if an item needs replacing. The attributes in each table allow for an extensive range of queries.
4
One to Many Relationship pubIDPubNameSalesContact 1Wiley 2Prentice Hall 3 Pearson Education 4McGraw-Hill 5East Sussex 6Everbestsales@everbest.com ISBNTitleEditionPubIDYearMediaCopies 0131451413Database concepts2 3 2005book1 1256748844Managing a Corporate Enterprise3 3 2005dvd1 One publisher can publish many resources Primary Key Foreign Key
5
SubNo SubName Faculty LIB_Subject SubNo* ISBN* LIB_ResSubject ISBN Title Ed PubID YearPub Media Copies LIB_Resource Many to Many Relationship SubNoISBN 310610471347116 310610131451413 31061 0072880678 21121 0471180327 314740072880678 subNosubNameFalculty 31061Database PrinciplesInformation Technology 21121Managing electronic business processesInformation Technology ISBNTitleEdpubIDYearMediaCopies 0131451413Database concepts232005book1 0471347116Data management : databases and organizations412003book2 0072880678Database design, application development, and administration242004book4 One resource can be for many subjects One subject can have many resources
6
Query on a single entity/table select * from LIB_author where augender = 'M'; auIDauNameauBirthauDeathaugender 1Kroenke, David M.M 2Watson, Richard TM 3Mannino, Micheal V.M 4McKeown, Patrick G.1943M 5Hartas, LeoM 6Prentice, SteveM select isbn, media from LIB_resource where media <> 'book'; ISBNMedia 1256748844dvd 1246450099Mmagazine Select all resources other than books Select all male authors
7
Query using Natural Join select subname, title, copies from lib_resource natural join lib_ressubject natural join lib_subject Where falculty = ‘Information Technology’; subNameTitleCopies Database PrinciplesDatabase concepts1 Database Principles Data management : databases and organizations2 Database FundamentalsDatabase design, application development, and administration4 Database PrinciplesDatabase design, application development, and administration4 Managing Electronic Business ProcessesMetamorphosis : a guide to the World Wide Web & electronic commerce1 List subject, resource and copies of all resources currently used by the faculty of Information Technology
8
select subname, title, copies from lib_resource, lib_subject, lib_ressubject where lib_resource.isbn = lib_ressubject.isbn and lib_subject.subno = lib_ressubject.subno and faculty = 'Information Technology'; subNameTitleCopies Database PrinciplesDatabase concepts1 Database Principles Data management : databases and organizations2 Database FundamentalsDatabase design, application development, and administration4 Database PrinciplesDatabase design, application development, and administration4 Managing Electronic Business ProcessesMetamorphosis : a guide to the World Wide Web & electronic commerce1 Query using Cross Product
9
Group By using Having show the authors who have authored more than 1 resource select auname, count(*) from lib_author, lib_resauthor, lib_resource where lib_resource.isbn = lib_resauthor.isbn and lib_resauthor.auID = lib_author.auID group by auname having count(*) > 1; auNameCount Jones, Katee K.2 Watson, Richard T.2
10
Query using a Sub Query selec t auname, aubirth from lib_author where aubirth <= all (select aubirth from lib_author where audeath is null and aubirth is not null); auNameauBirth McKeown, Patrick G.1943 show the ‘known’ oldest author who is still alive
11
Self Join Select all authors who authored two books (assuming no author has Authored more than two books) and the ISBN of each book. select au.auname, resau1.isbn as book1, resau2.isbn as book2 from lib_resauthor resau1, lib_resauthor resau2, lib_author au where resau1.auid = au.au and resau2.auid = au.auid and resau1.isbn < resau2.isbn; auNameBook1Book2 Watson, Richard T.04711803270471347116 Jones, Katee K.1246450099M1256748844
12
Data Integrity – CHECK Constraints Create table LIB_Author ( values go here…. auBirthCHAR(4), auDeathCHAR(4), auGenderTEXT, CONSTRAINT LIB_Author_AuBirth CHECK ((AuBirth < AuDeath) AND (AuBirth >= 0000) AND (AuBirth <= 9999)), CONSTRAINT LIB_Author_AuDeath CHEck (AuDeath > AuBirth), CONSTRAINT LIB_Author_AuGender CHECK (AuGender IN ('M','F')) );
13
SQL Syntax for Actions Create table LIB_ResCategory( catIDINTEGER, ISBNTEXT, CONSTRAINT LIB_ResCategoryPk PRIMARY KEY (CatID,ISBN), CONSTRAINT LIB_ResCategoryFk_INVALID_ISBN FOREIGN KEY (ISBN) REFERENCES LIB_Resource (ISBN) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT LIB_ResCategoryFk_INVALID_CatID FOREIGN KEY (CatID) REFERENCES LIB_Category (CatID) ON DELETE RESTRICT ON UPDATE CASCADE ); This will delete/update the entry of the isbn in Lib_rescategory if the resource is deleted/updated from Lib_resource This will delete/update the entry of the isbn in Lib_rescategory if the resource is deleted/updated from Lib_resource This will restrict the deletion of a category if there are still resources in the category. It will also update any changes in catID from LIB_category to the matching catID in LIB_resCategory. This will restrict the deletion of a category if there are still resources in the category. It will also update any changes in catID from LIB_category to the matching catID in LIB_resCategory.
14
Creating a View create view booksonloan ( isbn, title, copyno, daysout, due ) as select lib_loan.isbn, title, lib_loan.copyno, '07 June, 2007' - dateloan, datedue from lib_resource, lib_copy, lib_loan where lib_resource.isbn = lib_copy.isbn and lib_copy.copyno = lib_loan.copyno and lib_copy.isbn = lib_loan.isbn ; ISBNTitlecopyNoDaysOutDue 0471347116Data management : databases and organizations1132007-06-25 0471347116Data management : databases and organizations210 2007-06-28 0131451413Database concepts1332007-06-05 1246450099MGreece and why it rocks1132007-06-25
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.