880 likes | 1.08k Views
IT 20303. Data Modeling for Logical Design Section 04. Relational Database Theory. Database Development Life Cycle Requirements Analysis/Design Produce Build/Test Production Maintenance. Relational Database Theory. What is a Data Model? A way to represent reality
E N D
IT 20303 • Data Modeling for Logical Design • Section 04
Relational Database Theory • Database Development Life Cycle • Requirements • Analysis/Design • Produce • Build/Test • Production Maintenance
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
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
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
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
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)
Relational Database Theory • The Entity-Relationship Approach • Represents reality using well-defined graphics and rules • Basic building blocks are “things” (entities) and relationships Member M Adopts 1 Animal
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
Relational Database Theory • Entity-Relationship Model: Basic Concepts • Entity • Thing, Object, Concept of interest to the enterprise • Each occurrence can be uniquely identified
Relational Database Theory • Entity-Relationship Model: Basic Concepts • Attribute • Property of an entity • Column
Relational Database Theory • Entity-Relationship Model: Basic Concepts • Relationship • Association between two (or more) entities
Relational Database Theory • Entity-Relationship Model: Basic Concepts • Entity Identifier • Attribute(s) whose value uniquely identifies an entity • Primary Key
Relational Database Theory • What is an Entity? • Physical entity types • Person • Building • Machine • Book • Usually Singular
Relational Database Theory • What is an Entity? • Conceptual entity types • Contract • Account • Order • Course
Relational Database Theory • What is an Entity? • Event entity types • Transaction • Shipment • Reservation • Phone Call • Seminar Offering
Relational Database Theory • Entity-Relationship Model: Diagrams • Example: • Soft Rectangle represents entities • Noun • Singular • Connecting Line represents relationships • Verb Member Adopts Animal
Relational Database Theory • Relationships have Characteristics • A relationship has Cardinality (Degree) One-to-One One-to-Many Many-to-Many
Relational Database Theory • Each entity’s participation is Mandatory or Optional • Cardinality & Optionality are based on business rules Mandatory Optional
Relational Database Theory • One:One Relationship • One Member adopts one animal • One Animal is adopted by one member Member Adopts Animal
Relational Database Theory • One:Many relationship • One member adopts one animal • One animal is adopted by many members Member Adopts Animal
Relational Database Theory • Many:Many relationship • One member adopts many animals • One animal is adopted by many members Member Adopts Animal
Relational Database Theory • Optionality: Participation in a Relationship Zoo Employee Cares for Animal
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
Relational Database Theory • Optional • An instance of the entity CAN participate in the relationship • Example: • Some employees do not take care of animals
Relational Database Theory • Data Modeling Example: Hospital • Sample Hospital Data • Ward Name: Liston • Ward Type: Orthopedic • # of Beds: 6 • Senior Nurse: J. Bryan
Relational Database Theory • Data Modeling Example: Hospital • Cont’d • Date of Birth: dd/mm/yy
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
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step • Identify Entities PATIENT WARD
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
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step 3. Select or create a Unique Identifier for each entity WARD Ward name Type No beds Sr nurse PATIENT Patient number Name Date of birth
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
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step 5. Determine Optionality Patient Ward
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step 6. Show Cardinality Patient Ward
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step 7. History – time affects cardinality Patient Ward
Relational Database Theory • Entity-Relationship Modeling: Step-by-Step 8. Resolve Many:Many relationship STAY Patient number Ward name Date PATIENT Patient number Name Date of birth WARD Ward name Type No beds Sr nurse
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
Relational Database Theory • Meaning of an Entity • Cont’d • Clarify exact meaning of an entity by: • Identifying several attributes • List examples • Documenting the meaning
Relational Database Theory • Document Precise definition of each entity (Should always do)
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
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
Relational Database Theory • E-R Model: • Entities • Course • Course # (PK) • Course Title • Duration • Author
Relational Database Theory • E-R Model: • Entities • Seminar • Seminar # (PK) • Date • Place • Type • Public • On-site • Course # (FK)
Relational Database Theory COURSE • E-R Model: 1 Optional Mandatory M SEMINAR
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
Relational Database Theory • E-R Model: • Entities • Division • Division # • Division Name
Relational Database Theory • E-R Model: • Entities • Employee • Employee # • Employee Name • Dept # (FK)