Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Prabir Shrestha 491-5302 Nay Lin Zaw 481-5231 Pramit Silwal 502-5407
October 2008 1
Contents
1. Brief review of the Enterprise 2. The E-R Diagram 2.1 Decisions made while choosing appropriate E-R
3 4
... 8
8
. 10
4. Intended Use of Database 5. Relational Database Schema 6. Relational SQL Database Definition 7. System Architecture Revisited
11 15 16 20
Therearetwokindsofcustomers:normalandpremium.Allcustomershavetobeonly oneofthetwotypes.Thedifferencebetweenthetwokindsisthatnormalcustomersgetto rentupto2DVDsusingtheiraccount,whereaspremiumcustomersgettorentupto4DVDs. Anotherprivilegetopremiumcustomersisthattheycanrequestupto2DVDs.That is,eveniftheDVDisnotavailableatthestore,thecustomercanrequesttoreservethatDVD forhim/herwheneveracopyisreturned.Normalcustomersdonothavetheprivilegeofdoing thisandcanonlyrentfromwhatsavailableinthestoreatthecurrenttime. EachcustomeriscanonlyrentDVDsifhe/shehasntexceededthequotaallocatedand ifhe/sheisnotbanned.Acustomercanbebannedbyanadmindependingonthesituation.For example,acustomermaybebannedfornotreturningDVDsforanextendedperiodoftimeor situationsmayarisewhentheshopnolongerwantstoserviceaparticularcustomer.Thisbanis atemporarybanandcanbechangedbyadminassituationchanges. ItistobenotedthateveryDVDentityhasauniqueIDhowevercanhavemultiple copies.EachcopyisidentifiedwiththecombinationofDVDIDandcopynumber.Whena customerrentsaDVD,he/sheactuallyrentsacopyoftheDVD.Acustomermayrentcopiesof thesameofdifferentDVDsaccordingtohis/herquota. WheneveraDVDisrentedbyacustomer,wemaintaintherentaldateaswellasthe returndate,ifthecustomerreturnstheDVDaftertheduedate,heischargedwithoverdue feesdependingonhowmanydayshesexceededhisduedate. Wemaintainatablewithinformationrelatedtodirectors.EveryDVD(meaningthe movie)hastobedirectedbyoneormoredirectors.Wealsomaintainatablewithinformation relatedtoactors.AgaineveryDVDhastohaveatleastoneactorinithowever,wemay maintaininformationofactorsanddirectorsthatdonotbelongtoanyDVDinthedatabase. ADVDmayhaveoneormoregenre(forexample,action,comedy,horror,etc.) ADVDmayalsohavemultiplekeywordsassociatedwithitsothatitseasierforthe customertosearchaDVDbasedonwordsthatsuggestthecontentsorwordsthatareincluded inthetitleoftheDVD.
9
Weaknesses:
Although we mentioned earlier that we have a huge user table, there is a chance of losing valuable user information if somehow parts or whole of the table is deleted. Dividing the table into a reasonable number of sub tables using minimal foreign keys could be a good strategy. We could have a borrow policy for example so that each borrow policy has extra information in addition to the quota and fine rates. For example a borrow policy might include users being or not being liable to damages caused to the DVD. But since out design is comparatively for a smaller application, this feature has been left out. In a real world situation, the user would want to search for movie titles using more than keywords and names. A better design would perhaps be to allow users to rate DVDs themselves and have blogs or some such feature that allows users to interact with themselves.
10
GO
12
GO
(@title,@rating,@yearPublished) SET@id=scope_identity()
15
CREATETABLEtblAdmins ( keepstrackofwho'sadmin UserIDintNOTNULL, PRIMARYKEY(UserID), FOREIGNKEY(UserID)REFERENCEStblUsers(ID), ) ALTERTABLEtblAdmins ADDCONSTRAINTfk_AdminCustomersFOREIGNKEY(ID)REFERENCEStblUsers(ID) ONDELETECASCADE ONUPDATECASCADE CREATETABLEtblNormalCustomers ( IDint, PRIMARYKEY(ID) ) ALTERTABLEtblNormalCustomers ADDCONSTRAINTfk_NormalCustomersFOREIGNKEY(ID)REFERENCEStblUsers(ID) ONDELETECASCADE ONUPDATECASCADE CREATETABLEtblPremiumCustomers ( IDint, PRIMARYKEY(ID) ) ALTERTABLEtblPremiumCustomers ADDCONSTRAINTfk_PremiumCustomersFOREIGNKEY(ID)REFERENCEStblUsers(ID) ONDELETECASCADE ONUPDATECASCADE CREATETABLEtblBelongsTo ( DVDintNOTNULL, GenreintNOTNULL, PRIMARYKEY(DVD,Genre), FOREIGNKEY(DVD)REFERENCEStblDVD(ID), FOREIGNKEY(Genre)REFERENCEStblGenres(ID), 17
) CREATETABLEtblContains { DVDintNOTNULL, KeywordintNOTNULL, PRIMARYKEY(DVD,Keyword), FOREIGNKEY(DVD)REFERENCEStblDVD(ID), FOREIGNKEY(Keyword)REFERENCEStblKeywords(ID), ) CREATETABLEtblCopies ( copyinformationofeachDVD DVDIDintNOTNULL, CopyNumberintIDENTITY(1,1)NOTNULL, PRIMARYKEY(DVDID,CopyNumber), FOREIGNKEY(DVDID)REFERENCEStblDVD(ID), ) CREATETABLEtblCustomers ( customerdetails UserIDintNOTNULL, IsBannedbitNOTNULL, IsPremiumbitNOTNULL, Preferencechar(30)DEFAULTNULL, PRIMARYKEY(UserID), FOREIGNKEY(UserID)REFERENCEStblUsers(ID), ) CREATETABLEtblDirectedBy { DVDintNOTNULL, DirectorintNOTNULL, PRIMARYKEY(DVD,Director) FOREIGNKEY(DVD)REFERENCEStblDVD(ID), FOREIGNKEY(Director)REFERENCEStblDirector(ID), ) 18
CREATETABLEtblDirectors ( IDintIDENTITY(1,1)NOTNULL, FirstNameNameTypeNOTNULL, LastNameNameTypeNOTNULL, PRIMARYKEY(ID) ) CREATETYPEGenreTypeFROMvarchar(50) CREATETABLEtblGenres ( IDintIDENTITY(1,1)NOTNULL, TitleGenreType, PRIMARYKEY(ID), UNIQUE(Title) ) CREATETYPETitleTypeFROMvarchar(50) CREATETABLEtblDvds ( IDintIDENTITY(1,1)NOTNULL, TitleTitleTypeNOTNULL, RatingintDEFAULT0, YearPublishedintNOTNULL, PRIMARYKEY(ID) ) CREATETYPEKeywordTypeFROMvarchar(50) CREATETABLEtblKeywords ( IDintIDENTITY(1,1)NOTNULL, wordKeywordType, PRIMARYKEY(ID), UNIQUE(word) ) CREATETABLEtblPlaysIn { ActorintNOTNULL, DVDintNOTNULL, PRIMARYKEY(Actor,DVD), FOREIGNKEY(Actor)REFERENCEStblActors(ID), 19
FOREIGNKEY(DVD)REFERENCEStblDVD(ID), ) CREATETABLEtblRents( rentaldetails CustomerintNOTNULL, DVDintNOTNULL, CopyNumberintNOTNULL, DueDatedatetimeNOTNULL, RentDatedatetimeNOTNULL, PRIMARYKEY(Customer,DVD,CopyNumber), ) CREATETABLEtblRequests ( detailsofrequestfordvdmadebypremiumcustomers PremiumCustomerintNOTNULL, DVDintNOTNULL, RequestDatedatetimeNOTNULL PRIMARYKEY(PremiumCustomer,DVD), FOREIGNKEY(PremiumCustomer)REFERENCEStblCustomers(UserID), FOREIGNKEY(DVD)REFERENCEStblDVD(ID), )