Guests Rooms All guests in the database One guest may have several stays. One stay has only one guest One stay may com- prise many rooms. One room may be used for many stays. Stays Boxes with index cards Guest Stay Room 1:m One-to-many relationship m:m Many-to-many relationship A class contains: objects = entities records Class = entity class table Entity-relationship data model 3. UID16.1 E/R data model for a hotel
Guest Stay Room 1:m One-to-many relationship m:m Many-to-many relationship A class contains: objects = entities records Class = entity class table Entity-relationship data model 4. Extra: Some index cards Guest Name: Address: Phone: Passport: John Simpson 456 Orange … … Room roomID: bedCount: Type: Price 1: Price 2: 12 2 Double Stay Pay by: Date Room /812 24/812 24/811 visa E/R model: Lists forbidden on a card Put the date here?
6. UID16.3A Resolve m:m with connection class name, address, phone, passport stayID, paymethod roomID, bedCount, type price1, price2 personCount, state (booked | occ | repair) Guest Stay RoomState Room Guests Rooms Stays RoomStates enumeration type date
Stay Service Type name, price Guest Stay Room State Room Service Received Service Type date, personCount, state (booked | occupied | repair) name, address1, address2, address3, phone, passport roomID, bedCount, type price1, price2 name, price date, quantity Guest stayID, paymethod, state (booked | in | out | canceled) E.g. Full breakfast 6$, Continental 4$, Telephone... Add to ServiceReceived: serviceType (fullBreakfast | continental |... ) Remove this class? 7. UID16.3B Hotel data model
Guest Stay RoomState Room 8. UID16.4 Relational data model Guest Stay RoomState Room stayIDguestIDpaymethod Cash Visa roomIDprice stayIDroomIDdatestate /8occ /8occ /8booked /8occ guestIDnameaddress John Si Orange Gr 33Lise Ha...Dysseg Yun ChenKirch... 6 Table (relation) Record Foreign key, reference Primary key - artificial Primary key - natural Using the database Who stays in room 11 today 24/8? Which rooms has John Simpson today? Guest Thomson books, what happens? Guest 38 is to be deleted - how? Total amount for room 13? Composite key
9. UID16.5 Data sources CarOwner A domain word may become: an entity an attribute a relationship something outside the model printout/computation “noise” Official source text When a car is registrated it gets a license number (shown on the license plate). The Vehicle Office also records the owner’s name and address, civil registration number or company tax file number, the make (producer and model), chassis number, fuel type (gas, diesel,...) and the registration date. The vehicle office sends a registration certificate to the primary owner or user, but it doesn’t show the civil registration number or the company registration number. More than one owner and user may be recorded. ?
10. UID16.6 Data dictionary D1:Class: Guest [Notes a, b... refer to guidelines] The guest is the person or company who has to pay the bill. A person has one or more stay records. A company may have none [b, c]. “Customer” is a synonym for guest, but in the database we only use “guest” [a]. The persons staying in the rooms are also called guests, but are not guests in database terms [a]. Examples E1.A guest who stays one night. E2.A company with employees staying now and then, each of them with his own stay record where his name is recorded [d]. E3.A guest with several rooms within the same stay. Attributes 1. name:Text, 50 chars [h] 2. passport:Text, 16 chars [h] Attribute missing in data model Guidelines for classes. Explain: a)Name in the system vs. name in domain b) Relationships to other classes c) Cases where connections are missing d) Concerns when creating or deleting an entity e) Typical and unusual examples
11. UID16.6 Data dictionary (cont.) D1:Class: Guest [Notes a, b... refer to guidelines] The guest is the person or company who has to pay the bill. A person has one or more stay records. A company may have none [b, c]. “Customer” is a synonym for guest, but in the database we only use “guest” [a]. The persons staying in the rooms are also called guests, but are not guests in database terms [a]. Examples E1.A guest who stays one night. E2.A company with employees staying now and then, each of them with his own stay record where his name is recorded [d]. E3.A guest with several rooms within the same stay. Attributes 1. name:Text, 50 chars [h] 2. passport:Text, 16 chars [h] Recorded for guests who are obviously foreigners [f, i]. Used for police reports in case the guest doesn’t pay [g]... The name stated by the guest [f]. For companies the official name since the bill is sent there [g]. Longer names exist, but better truncate at registration time than at print out time [g, j]. Guidelines for attributes. Explain: f) From where in the domain do we get the values? g) What are they used for in the domain? h) Possible values i)Special values, e.g. blanks, and when j)Typical and unusual examples
12. UID16.7 Network model: Flight routes Chicago ColumbusWashington NewYork AA331 Route City Route: AA331. Mon, Wed ArrDep Chicago10:45 Columbus11:4012:20 Washington13:3014:15 New York15:10 Leg Route Leg City Next 1:1 relation From To attributes?
16. UID16.10 Network model: road map Road ?? Section ?? Point ?? Copyright Melway Publishing Pty Ltd. Reproduced from Melway Edition 31 with permission.
17. UID16.11 Sub-classes: Internet car broker Customer custID phone1 phone2 Advertisement fromDate toDate make year miles color state price text announce see? Attributes in UML way Class Dealer name address... Private userID cardID expiry Sub-classes E/R solution 1: Constraint - Priv or Dealer Customer Dealer Private custID, phone1... subClass (priv|dealer) custID, userID...custID, name...
Customer custID phone1 phone2 Advertisement fromDate toDate make year miles color state price text announce see? Attributes in UML way Class Dealer name address... Private userID cardID expiry Cust&Priv Dealer E/R solution 2: Always space for Private E/R solution 3: Customer may have several roles. All possible attributes. Many nil - depending on role. Customer Role role (private | dealer | reader), userID, name, address, cardID, expiry, custID 18. UID16.11 Sub-classes (cont.)
A A 1:m variants: Each A has zero or more Bs Each B has one A Each A has one or more Bs Each B has zero or one A Cardinality : A Each A owns one or more Bs Each B belongs to one A owns belongs Referential integrity B B B A B 1:1 variant: Each A has a B (don’t know about zero) Each B has zero or one A m:m variant Each A has one or more Bs Each B has zero or more As A B 19. UID16.12A Notational variations
A B 1:1 1: UML notation Each A has one or more Bs Each B has one A A B 0:11:99 Each A has one to 99 Bs Each B has zero or one A Stay RoomState 1:m: Move attributes to RoomState and make a 1:m crow’s foot. date, state Stay Room #persons Diamond notation m:m: Make diamond a connection class m m m UID16.12A Notational variations (cont.)
21. SR2.2F Transformation rules A B C A C A B C A C Two feet facing the same way make one long foot Two feet facing opposite ways make many-to-many Stay Room Stay Room state Room Resolve many- to-many with a connection box
Line Class activity Request hour Room hour Room Contract period Activity Class hours Time table User authoriz Authoriz type Room property Property wish Room wish Building wish Building 1:1 0: 1: 1:1 0: 0:1 1: 1:1 0: 1:1 1: 1:1 0: 0:1 1:1 0: 1:1 1: 1:1 0: 1:1 0: 0:1 0: 1:1 0: 1:1 0:1 1:1 0:1 0: 1: 0: 22. UID16.12B UML and broken connectors
Line Class activity Request hour Room hour Room Contract period Activity Class hours Time table User authoriz Authoriz type Room property Property wish Room wish Building wish Building 23. UID16.12B Room allocation system in E/R notation
24. UID16.14A Normalization and first normal form First normal form: For each primary key, there must be a fixed number of fields of fixed length. Variable length attribute Purpose: Avoid redundancy (same data several places) Find the “true” objects Ensure “table format” Employee qualifications empIDnamedeptIDdeptNameCourses 100Thomson5SalesWindows, Word, Access 101Smith7AccountingWord 102Bunting5SalesWord, Access Course list Employee qualifications empIDnamedeptIDdeptNamecourseIDcourseNameyear 100Thomson5Sales1Windows Thomson5Sales2Word Thomson5Sales3Access Smith7Accounting2Word Bunting5Sales2Word Bunting5Sales3Access2001 Fixed length attributes Key repeatedRedundancy Variable number of fields for same key
Cure: Move variable-length stuff to a separate table. CoursesTaken empIDcourseIDcourseNameyear 1001Windows Word Access Word Word Access2001 EmployeeCourseTaken Employees empIDnamedeptIDdeptName 100Thomson5Sales 101Smith7Accounting 102Bunting5Sales 25. UID16.14A Normalization and first normal form (cont.)
26. UID16.14B Second normal form Second normal form: First normal form + Non-key fields must depend on entire key. Doesn’t depend on empID CoursesTaken empIDcourseIDcourseNameyear 1001Windows Word Access Word Word Access2001 Cure: Move fields depending on a partial key to a separate table. CoursesTaken empIDcourseIDyear Courses courseIDcourseName 1Windows 2Word 3Access CourseCourseTaken
27. UID16.14C Third normal form & final model Third normal form: Second normal form + Non-key fields must be independent. Employees empIDnamedeptIDdeptName 100Thomson5Sales 101Smith7Accounting 102Bunting5Sales Depends only on deptID Omit deptID and use deptName as the key? Cure: Move interdependent fields to a separate table. DepartmentEmployee Employees empIDnamedeptID 100Thomson5 101Smith7 102Bunting5 Departments deptIDdeptName 5Sales 7Accounting CourseCourseTaken name year deptName courseName
28. UID16.14D Hotel system normalization Rooms roomIDtypebedCountprice1price2 011Double, bath Single, toilet Double, bath Single, toilet Double, bath Single, bath Depend only on type Hard to change prices for 400 rooms Rooms roomIDroomType RoomTypes roomTypedescriptionbedCountprice1price2 1Double, bath Double, toilet Single, toilet160 4Single, bath Third normal form: Easy to change prices for 8 room types