190 likes | 379 Views
Lecture 5. 21/10/13. An Associative Entity. A many to many relationship hides another entity In order to alleviate this, an associative entity is created An associative entity is a combination of an entity and relationship
E N D
Lecture 5 21/10/13
An Associative Entity • A many to many relationship hides another entity • In order to alleviate this, an associative entity is created • An associative entity is a combination of an entity and relationship • The primary key of the associative entity is comprised of the two primary keys of the two entities from which it was derived
Many-to-Many Relationship (N:M) • Many-to-many relationships occur where many instances of an entity relate to many instances of a second entity • These relationships usually contain a hidden entity which should be extracted • Usually N:M relationships are broken into one or more pairs of one-to-many relationships
Associative Entities • The many to many cardinality should be positioned towards the associative entity. • An associative entity may also be referred to as a link entity.
Creating an Associative Entity Doctor Patient Has an appointment with
Creating an Associative Entity Doctor Patient conducts present at Appointment
Another example Engineer Project Works on Worked on Works on Engineer Contract Project
Another example Film Actor Appears in makes contains Film Appearance Actor
Primary and Foreign Keys • We have stated that a primary key or key attribute uniquely identifies an entity instance e.g. Customer ID. • A foreign key is an attribute that appears as a non-key attribute in one table (entity) and as the primary key of another table (entity).
Foreign Key Tutorial Schedule Tutor Is assigned
Data Modeling Concepts: Generalization Generalization – a concept wherein the attributes that are common to several types of an entity are grouped into their own entity. Supertype – an entity whose instances store attributes that are common to one or more entity subtypes. Subtype – an entity whose instances may inherit common attributes from its entity supertype And then add other attributes that are unique to the subtype.
Example: Is cared for by Physcian Patient Is a Is a OutPatient Resident Patient Bed Is assigned
Example • Patient is the supertype which is conneted to two subtypes Outpatient and Resident Patient • Attributes that are shared by all patients are associated with the supertype • Attributes that are unique to a particular subtype are only associated with that subtype • Relationships in which all types of patients participate are associated with the supertype • Relationships in which only a subtype participates is associated only with the relevant subtype.
Example: Admit_Date Physician_id Patient_Id Is cared for by Physcian Patient Patient_Name Is a Is a OutPatient Resident Patient Bed Is assigned Date Discharge Checkback Date Bed_Id
What is a Good Data Model? • A good data model is simple. • Attributes that describe any given entity should describe only that entity. • Each attribute of an entity instance can have only one value.
What is a Good Data Model? • A good data model is essentially nonredundant. • This means: • Each data attribute, other than foreign keys, describes at most one entity. • Look for the same attribute recorded more than once under different names. • A good data model should be flexible and adaptable to future needs.
Data Analysis Data analysis – a technique used to improve a data model for implementation as a database. Goal is a simple, nonredundant, flexible, and adaptable database.
Recap • An entity is….. • A primary key is…. • An attribute is…. • A relationship is…. • Cardinality is….
Entity Relationship Diagram (ERD) Exercise - vehicle rental company • AllCars wishes to create a system to monitor the rental of vehicles to clients. The company has various outlets and each outlet has staff including a Manager and a number of mechanics. Each outlet has a stock of vehicles for rent that may be rented by clients for various periods of time. Each rental agreement between the customer and AllCars is identified through a rental number. A client must take out insurance cover for each vehicle rental period and a vehicle is checked for faults after each rental. • Draw an ERD that represents the system outlined above. • Include the cardinality and for the relationships identified in the model.