Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT 20303 Data Modeling for Logical Design Section 04.

Similar presentations


Presentation on theme: "IT 20303 Data Modeling for Logical Design Section 04."— Presentation transcript:

1 IT 20303 Data Modeling for Logical Design Section 04

2 Relational Database Theory Database Development Life Cycle –Requirements –Analysis/Design –Produce –Build/Test –Production Maintenance

3 Relational Database Theory What is a Data Model? –A way to represent reality –A schematic of data items and relationships –A “blueprint” for the database

4 Relational Database Theory Why do people use data models? –To better understand the world we are modeling –To “picture” the conceptual view of the database –To better communicate between people –To arrive at a common understanding of meaning of terms

5 Relational Database Theory When do we make a data model? –For a specific application, begin in the definition phase –For multiple applications, in a long-range planning activity An information resource management activity A data administration activity –When in doubt - model

6 Relational Database Theory Building a database is a learning process –At the beginning, we only know what things are important –We identify the major things and call them Entities –We accumulate Attributes and associate them with entities –We determine how to identify each occurrence of an entity – PK

7 Relational Database Theory Cont’d –We identify relationships between entities – FK –We accumulate rules for the entities and relationships – Constraints –We put it all together in a model and check it out with users –This is called top-down data modeling (This is good to do)

8 Relational Database Theory The Entity-Relationship Approach –Represents reality using well-defined graphics and rules Basic building blocks are “things” (entities) and relationships Member Animal M 1 Adopts

9 Relational Database Theory Advantages –Theoretical foundation (Set Theory) –Good for communication –Build E-R Model, then translate to any type of RDBMS Disadvantages –Different (yet another new thing to learn) –Must translate to the relational model

10 Relational Database Theory Entity-Relationship Model: Basic Concepts –Entity Thing, Object, Concept of interest to the enterprise Each occurrence can be uniquely identified

11 Relational Database Theory Entity-Relationship Model: Basic Concepts –Attribute Property of an entity Column

12 Relational Database Theory Entity-Relationship Model: Basic Concepts –Relationship Association between two (or more) entities

13 Relational Database Theory Entity-Relationship Model: Basic Concepts –Entity Identifier Attribute(s) whose value uniquely identifies an entity Primary Key

14 Relational Database Theory What is an Entity? –Physical entity types Person Building Machine Book Usually Singular

15 Relational Database Theory What is an Entity? –Conceptual entity types Contract Account Order Course

16 Relational Database Theory What is an Entity? –Event entity types Transaction Shipment Reservation Phone Call Seminar Offering

17 Relational Database Theory Entity-Relationship Model: Diagrams –Example: –Soft Rectangle represents entities Noun Singular –Connecting Line represents relationships Verb Member Animal Adopts

18 Relational Database Theory Relationships have Characteristics –A relationship has Cardinality (Degree) One-to-OneOne-to-Many Many-to-Many

19 Relational Database Theory Each entity’s participation is Mandatory or Optional Cardinality & Optionality are based on business rules Mandatory Optional

20 Relational Database Theory One:One Relationship –One Member adopts one animal –One Animal is adopted by one member Member Animal Adopts

21 Relational Database Theory One:Many relationship –One member adopts one animal –One animal is adopted by many members Member Animal Adopts

22 Relational Database Theory Many:Many relationship –One member adopts many animals –One animal is adopted by many members Member Animal Adopts

23 Relational Database Theory Optionality: Participation in a Relationship Zoo Employee Animal Cares for

24 Relational Database Theory Mandatory –Every instance of the entity MUST participate in the relationship –Example: Every animal is cared for by at least one employee

25 Relational Database Theory Optional –An instance of the entity CAN participate in the relationship –Example: Some employees do not take care of animals

26 End 09-14-05

27 Relational Database Theory Data Modeling Example: Hospital –Sample Hospital Data Ward Name:Liston Ward Type:Orthopedic # of Beds:6 Senior Nurse:J. Bryan

28 Relational Database Theory Data Modeling Example: Hospital –Cont’d –Date of Birth: dd/mm/yy Patient NoPatient NameDate of Birth 45812Carter, D.21/02/65 71384Willis, R.08/10/46 69355Barnes, G.17/06/41

29 Relational Database Theory Requirements determines boundaries of data modeling –Data model does contain data about Ward Patients –Data model does not contain data about Color of walls in ward Color of patients hair Springiness of the beds in the ward

30 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 1.Identify Entities PATIENTWARD

31 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 2. Associate Attributes with entities PATIENT Patient number Name Date of birth WARD Ward name Type No beds Sr nurse

32 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 3. Select or create a Unique Identifier for each entity PATIENT Patient number Name Date of birth WARD Ward name Type No beds Sr nurse

33 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 4. Identify Relationship between entity PATIENT Patient number Name Date of birth WARD Ward name Type No beds Sr nurse Is assigned to Has assigned to it

34 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 5. Determine Optionality PatientWard

35 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 6. Show Cardinality PatientWard

36 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 7. History – time affects cardinality PatientWard

37 Relational Database Theory Entity-Relationship Modeling: Step- by-Step 8. Resolve Many:Many relationship PATIENT Patient number Name Date of birth WARD Ward name Type No beds Sr nurse STAY Patient number Ward name Date

38 Relational Database Theory Meaning of an Entity –What is a patient? In-patient Out-patient Psychiatric patient Baby born in hospital Baby born outside hospital Current patient Former patient

39 Relational Database Theory Meaning of an Entity –Cont’d Clarify exact meaning of an entity by: –Identifying several attributes »List examples –Documenting the meaning

40 Relational Database Theory Document Precise definition of each entity (Should always do) Entity NameEntity Description 20. Patient A person with a specific disease or condition who receives treatment within a county. An entity on the patient master index. This may be a person who uses a hospital bed in order to receive clinical care/treatment or someone attending a clinic, day-care facility, etc. It also includes people in the community receiving care under a “Nursing Care in the Community” or a hospice program. This also includes patients on the elective admission list who are awaiting elective admission. The local authority of residence should also be recorded for each patient. This can be derived from the postcode.

41 Relational Database Theory Drawing an E-R Diagram –Identify the entities –Write (make up) a few attributes for each entity –Designate the unique identifier (PK) –Identify the relationship (FK goes on the many side) –Show cardinality and optionality for each relationship

42 Relational Database Theory E-R Modeling Exercise: –A Seminar Company A seminar company offers more than 100 different courses –Each course has a unique course number and a title The company schedules thousands of seminars annually –Each seminar is the presentation of one specific course –A seminar is either public or on-site

43

44 Relational Database Theory E-R Model: –Entities Course –Course # (PK) –Course Title –Duration –Author

45 Relational Database Theory E-R Model: –Entities Seminar –Seminar # (PK) –Date –Place –Type »Public »On-site –Course # (FK)

46 Relational Database Theory E-R Model: COURSE SEMINAR Optional Mandatory 1 M

47

48 Relational Database Theory E-R Modeling Exercise: –A Personnel Database A company has four divisions Each employee works for a department Each department reports to one of the divisions

49 Relational Database Theory E-R Model: –Entities Division –Division # –Division Name

50 Relational Database Theory E-R Model: –Entities Employee –Employee # –Employee Name –Dept # (FK)

51 Relational Database Theory E-R Model: –Entities Department –Dept # –Dept Name –Div # (FK)

52 End 09-16-05

53 Relational Database Theory Optionality: Four Possibilities A DEPARTMENT EMPLOYEE Works for

54 Relational Database Theory Optionality: Four Possibilities B DEPARTMENT EMPLOYEE Works for

55 Relational Database Theory Optionality: Four Possibilities C DEPARTMENT EMPLOYEE Has working for it

56 Relational Database Theory Optionality: Four Possibilities D DEPARTMENT EMPLOYEE Has working for it

57 Relational Database Theory Optionality on the “many” side –Can be declared as a constraint in the database –Determines whether the foreign key must be not null

58 Relational Database Theory Determining Optionality & Cardinality –Optionality & Cardinality Specify lower and upper bounds of each entity’s participation in the relationship Use one of the following templates

59 Relational Database Theory Template 1 (B) –One employee (may/must) work for (one and only one/one or more) department Template 2 (B) –One employee works for a minimum of (0/1) and a maximum of (1/many) department

60 Relational Database Theory Use either template –Read each relationship twice Left to Right Right to Left

61 Relational Database Theory E-R Model: DIVISIONDEPARTMENT Reports to EMPLOYEE Works for B

62 Relational Database Theory E-R Modeling Exercise: –A Supplier-Parts Database A company purchases many parts from its suppliers –Each part has only one supplier A supplier can supply zero, one, or many parts –One _____(may/must) _____ (one and only one/one or more) ______

63

64 Relational Database Theory E-R Model: SUPPLIER PART Supplies

65 Relational Database Theory E-R Modeling: Resolving a M:N Relationship –Establish a “Linker” entity (associative entity) –Make two 1:M relationships with the linker entity –Make the linker entity identifier the composite of the entity identifiers from the existing entities –Assign attributes to the linker entity that belong to the relationship

66 Relational Database Theory E-R Model: –M:N SUPPLIER PART

67 Relational Database Theory E-R Model: –1:M – 1:M SUPPLIER Supplier ID PART Part No SUPPLIER/PART Supplier ID Part No supplies is supplied by

68

69 Relational Database Theory E-R Modeling Exercise: –A Warehouse-Products Database A company has six warehouses –Each warehouse stocks at least 50 different products The company markets approximately 500 products in a year –Approximately 300 products are in stock at any one time

70 Relational Database Theory E-R Model: WAREHOUSE Warehouse # Location INVENTORY Warehouse # Product # Stocked in PRODUCT Product # Product Name Stocks Original N:M

71 Relational Database Theory Guidelines to Develop an E-R Diagram –Identify the Major Entities –Identify the Attributes for each entity –Determine the Unique Identifier(s) –Identify the Relationships –Assign Cardinality –Turn Multivalued attributes into another entity –Determine Optionality –Resolve M:N Relationships

72 End 09-19-05

73 Relational Database Theory Recursive Relationships: 1:M –A recursive relationship is a relationship between multiple occurrences of the same entity

74 Relational Database Theory Recursive Relationships: 1:M –There is a binary (1:M) recursive relationship between employees One employee supervises other employees –The supervisor is also an employee Empno and Mgr have the same domain (Employee)

75 Relational Database Theory Recursive Relationships: 1:M Cont’d EMPLOYEE EmpnoEnameDobStartdateJobMgrSalDeptno… EMPLOYEE Empno Ename Mgr …. Supervises

76 Relational Database Theory Example of a M:N Recursive Relationship –“Bill of Materials” is a recursive relationship between parts One part can be an assembly, which contains parts One part can be a component, contained in an assembly –Resolve M:N recursive relationship Into two 1:M relationships

77 Relational Database Theory Cont’d PART Part # …. Contains ASSEMBLY Assembly Part # Component Part # Qty … PART Part # … ContainsIs contained in

78 Relational Database Theory Entity Subtypes and Supertypes –An entity supertype can have several subtypes –Different subtypes usually have different attributes

79 Relational Database Theory Cont’d EMPLOYEE Empno Ename Job type SALARIED EMPLOYEE Wage/month HOURLY EMPLOYEE Wage/hour Shift Is A SUPERTYPE SUBTYPE

80 Relational Database Theory Mapping the E-R Diagram to the Relational Database –Each entity becomes a Table –Each attribute becomes a Column –Unique Identifier becomes the PK –Each 1:M becomes a FK on the Many Side

81 Relational Database Theory Cont’d –Optionality determines if the FK can be Null –Each M:N becomes a New Table Primary key is a composite of PK’s on each table Attributes of the relationship become columns Any unresolved M:N must be resolved at this time

82 Relational Database Theory Mapping Subtypes and Supertypes –Implementation Choices One Table for the Entity –Includes all attributes of supertype + all attributes of each subtype

83 Relational Database Theory Cont’d –One table for each subtype Includes all attributes of supertype in each table –One table for each subtype plus one table for the supertype

84 Relational Database Theory Variations in Data Modeling Graphics: Entities & Relationships 1:1 11 11

85 Relational Database Theory Variations in Data Modeling Graphics: Entities & Relationships 1:M 1M 1M

86 Relational Database Theory Variations in Data Modeling Graphics: Entities & Relationships M:N MN MN

87 Relational Database Theory A “GOOD” Data Model –Accurately Models the Real World or Application Domain As defined by the requirements –Aids in Communications –Identifies all the Important Entities and Relationships

88 Relational Database Theory Questions?


Download ppt "IT 20303 Data Modeling for Logical Design Section 04."

Similar presentations


Ads by Google