cis 4365 entity relationship diagrams
DESCRIPTION
CIS 4365 Entity Relationship Diagrams. Chapter3 :. Entity-Relationship Modeling:. Part 2. CIS 4365 Entity Relationship Diagrams. Your Individual Project. We will develop the ERD as a class; you must execute complete the project on your own. - PowerPoint PPT PresentationTRANSCRIPT
1
Chapter3:Entity-Relationship Modeling:
CIS 4365 Entity Relationship Diagrams
Part 2
Your Individual Project
2CIS 4365 Entity Relationship Diagrams
• We will develop the ERD as a class; you must execute complete the project ON YOUR OWN
• We will go to the lab to create the tables• I will give you the data to populate the tables• I will help you get you get started with your queries
PLEASE NOTE:• When I say Individual, I mean you should do it by yourself• You will NOT learn if your friend gives you the answers• I WANT YOU TO LEARN!
• I still get paid (not much).• I tried.
• IF YOU WON’T LEARN, YOU ARE WASTING YOUR MONEY!
Your Individual Project
3CIS 4365 Entity Relationship Diagrams
• Consider the following:
“You work for a hospital. The Head Administrator has told you that he suspects that Dr. Smith, as well as all of the other physicians which she supervises, has been pre-scribing too much Codeine for their patients. He wants a list of all of Dr. Smith’s patients, their illnesses, and what drugs were given to those people. If it looks suspicious, he will later want the same list for each of the physicians Dr. Smith supervises.”
• There is one additional constraint we will add:
“Each patient can have only one primary physician.”
Your Individual Project
4CIS 4365 Entity Relationship Diagrams
• Simplifying/Elucidating the Problem Semantics:
“A Physician Treats many Patients.” Given“A Patient is Treated by only one Primary Physician.” Given
“Many Patients Suffer many Illnesses.” Inferred
“Many Illnesses Require many Drugs”
Inferred
“A Physician Supervises many other Physicians.” Inferred“A Physician is Supervised by another Physician.” Inferred
We can now identify (based in the original Statement) All of the Entities and their Cardinality and, (implicitly), their constraints
“Many Illnesses are Suffered by many Patients.”
“Many Drugs are Required by many Illnesses.” InferredInferred
Your Individual Project
5CIS 4365 Entity Relationship Diagrams
• 1st Relationship:
Physician Treats Patient
Given 1 Physician, how many Patients?Mandatory?
Given 1 Patient, how many Physicians?Mandatory?
Your Individual Project
6CIS 4365 Entity Relationship Diagrams
• 1st Relationship:
Physician Treats Patient
• Attributes??
Name
Address
Specialty
Name
Address
What is wrong with these attributes??
Your Individual Project
7CIS 4365 Entity Relationship Diagrams
• 1st Relationship:• What if, in addition to looking for a physician (or patient) only
by name, we look for them by name AND address?? • Probably NOT a good idea (think: George Foreman)
• Solution: Assign a UNIQUE identifier:
Physician Treats Patient
PhysID
Address
Specialty
Name
Name
Address
PatID
Your Individual Project
8CIS 4365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?• We could place the Patient Information (e.g., using the primary
key PatID) as an attribute in the Physician Entity
Physician PhysID
Address
Specialty
Name
PatIDa PatIDb °°°°°° PatID??
I think we have a problem!!!
Your Individual Project
9CIS 4365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?
• Because this is a relational database, we need what is the maximum number of patients a patient can have:
Physician PhysID
Address
Specialty
Name
PatIDa PatIDb °°°°°° PatID??
None? Maybe the physician has no patients presently admitted
One? Maybe they are the President’s Physician
A Million? Maybe they are ambulance chasers
Let’s Assume the Maximum is 1,000.
Your Individual Project
10CIS 4365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?
• If these our field sizes are:
Physician PhysID
Address
Specialty
Name
PatIDa PatIDb °°°°°° PatID??
Field #BytesPhysID 9Name 30Address 50Specialty 30
119Plus 9 bytes per Patient
• That means that we would need to increase the number of bytes needed FOR EACH RECORD to: 119+ 1,000 * 9 = 9,119 Bytes
• If there are 300 physicians in the PHYSICIAN Table, the table will require 400 * 9,119 = 3,647,600 Bytes (The vast majority of Patient fields will be NULL)
Versus the 300 *119 = 35,700 bytes it would be otherwise
Your Individual Project
11CIS 4365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?• Note that we have seen this situation before:
Specialty
Physician PhysID
Address
NamePatIDa °°°°°° PatID??
Patients
A Multivalued Attribute – Repeating Groups
PhysID Other PatID1 PatID2 PatID3 °°°123456789 °°° 543210987 °°° °°° °°°234567890 °°° 765432109 321098765 °°° °°°345678901 °°° 109876543 654321098 210987654 °°°456789010 °°° 432109878 109876543 987654321 °°°
PatID Other987654321 °°°109876543 °°°765432109 °°°654321098 °°°543210987 °°°432109876 °°°321098765 °°°210987654 °°°432109878 °°°Not Good!
Your Individual Project
12CIS 5365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?• Let’s try putting the foreign key in the Patient table
Physician Treats Patient
PhysID
Address
Specialty
Name
Name
Address
PatID
Physician
Note that because this is a 1:M relationship, we only have to add 1 additional field to the Patient Table
Your Individual Project
13CIS 5365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?• Let’s try putting the foreign key in the Patient table• Notice the storage savings (Assume that table Patient, without the
foreign key, require 100 bytes/record, & that there are 5,000 records)
Foreign Key in PHYSICIAN Foreign Key in PATIENT
PHYSICIAN 3,647,600 Bytes PATIENT 500,000 Bytes
35,700 Bytes 545,000 Bytes
BOTH 4,147,600 Bytes 580,700 Bytes
• A savings of 3,566,900 Bytes
How would the tables in this relationship look like?
Your Individual Project
14CIS 5365 Entity Relationship Diagrams
• 1st Relationship:• How do we relate a Physician to their Patients?
Physician Table Attributes/Fields
Patient Table Attributes/Fields
PhysID
NameSpecialty
Address
PatID
NameAddress
Physician
Is the field Physician actually placed in the Patient Table???
YES – See the next slide
1
M
Your Individual Project
15CIS 5365 Entity Relationship Diagrams
• 1st Relationship:
PhysID °°°123456789234567890345678901456789012567890123
Physician Table PatID °°° Physician
255356278 456789012344244256 234567890399872889 234567890401293648 456789012450192243 345678901589021099 345678901620896798 567890123730927457 456789012801928364 123456789822981630 234567890
Patient Table
Our first rule is that in a 1:M relationship, the foreign key ALWAYS goes on the side of the many
Your Individual Project
16CIS 5365 Entity Relationship Diagrams
• 1st Relationship:What do we do with the composite key ADDRESS?
• In this case, we simple decompose it into the fields we will use
PhysIDName
Specialty
Street
CityState
ZipCode
PatIDName
Street
City
State
ZipCode
Physician
Physician Table Attributes/Fields
Patient Table Attributes/Fields
1
M
Your Individual Project
17CIS 5365 Entity Relationship Diagrams
• 1st Relationship:• Our actual tables might appear as:
PhyID Last First Street City State Specialty234567890 Kervorkian Jack 32 Viscount El Paso TX Euthanasia345678901 Zhivago Yuri 19 Redd Rd El Paso TX Cardiology456789012 Rebenneck Mac 65 Piano St. La Union NM Orthopedics
PatID Last First Street City State Physician255356278 Sotomayor Sonya 12 Oregon El Paso TX 456789012399872889 Bush W 123 Mesa El Paso TX 234567890589021099 Mubarack Hosni 18 Hideout El Paso TX 345678901620896798 Martinez Susana 7 Mayor St Anthony NM 456789012730927457 Lohan Lindsay 12 Necklace El Paso TX 345678901
• We Now Know:• Sonya Sotomayor has Dr. Rebenneck as her physician• W. Bush has Dr. Kervorkian as his physician• Hosni Mubarark has Dr. Zhivago as his physician• Susana Martinez has Dr. Rebenneck as her physician
Your Individual Project
18CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:
Patient Suffers Illness
Given 1 Patient, how many Illnesses?Mandatory?
Given 1 Illness, how many Patients?Mandatory?
Note that the true constraints of a problem are not always stated nor readily inferred ---
Your Individual Project
19CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• What about the attributes of Illness?• Depends ---- let’s keep it simple:
Illness
IllCode Description
Your Individual Project
20CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• Let’s try putting the foreign key in table Patient
Patient PatID
Address
Physician
Name
IllCodea IllCodeb °°°°°° IllCode??
OOPS!!!
Your Individual Project
21CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• The let’s try putting the foreign key in table Illness
Illness IllCode
Description
PatIDa PatIDb °°°°°° PatID??
This is as bad as the other relationship !!
Your Individual Project
22CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• We’re going to have to find a different solution.
• We will have create a separate table to link the two tables together.
What Table??
• How about a table called Suffers?
But Suffers is a relationship, NOT a Table!
• Why can’t it be both?
Your Individual Project
23CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• Table SUFFERS will become an ASSOCIATIVE ENTITY
Patient Suffers Illness
PatID
Address
Physician
Name
IllCode
Descript.But how will the tables be
related??
Your Individual Project
24CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• We must use unique keys from each of the tables as foreign
keys in Table SUFFERS
PatID IllCode
We can now link a Patient
With an Illness
Doesn’t every table also need a PRIMARY Key??
Patient Suffers Illness
PatID
Address
Physician
Name
IllCode
Descript.
Your Individual Project
25CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• We can use the two keys (PatID and IllCode) TOGETHER as
the Primary Key
Suffers
PatID IllCode
This is known as concatenation
• Notice that BOTH keys are primary keys AND foreign keys
Your Individual Project
26CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• Concatenation is the operation of joining two character strings
end-to-end.• For example, suppose I have two strings:
A = “How now” And B = “Brown Cow”• Then:
A + B = “How now Brown Cow”
So the two field are merged together into one field??• No.• But the primary key considered as if they were.
How does all this work??
Your Individual Project
27CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• Assume that one record in table SUFFER appears as:
Patient IllnessSuffersPatID Name
°°° °°°547286579 Clara Schuman
°°° °°°
IllCode Description°°° °°°
A896507 Broken Left Ulna°°° °°°
PatID IllCode°°° °°°
547286579 A896507°°° °°°
• We know that Clara Schuman suffered a broken left ulna
There is a problem here!!!
Your Individual Project
28CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• The problem is that the concatenated primary key is NOT unique
Patient IllnessSuffersPatID Name
°°° °°°547286579 Clara Schuman
°°° °°°
IllCode Description°°° °°°
A896507 Broken Left Ulna°°° °°°
PatID IllCode°°° °°°
547286579 A896507°°° °°°
547286579 A896507
• What if, in the future, Clara again breaks her left Ulna:
• In both cases, the fields are:
547286579 A896507
A violation of Entity Integrity!!!
Your Individual Project
29CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• We could add a TIMESTAMP to the associative Entity:
Suffers
PatID IllCode DateSeen
• Notice that our concatenated primary key is now:
PatID + IllCode + DateSeen
Your Individual Project
30CIS 5365 Entity Relationship Diagrams
• 2nd Relationship:• How do we relate a Patient to their Illnesses?• Our tables would appear as:
Patient IllnessPatID Name
°°° °°°547286579 Clara Schuman
°°° °°°
IllCode Description°°° °°°
A896507 Broken Left Ulna°°° °°°
PatID IllCode DateSeen°°° °°° °°°
547286579 A896507 8/20/2009°°° °°° °°°
547286579 A896507 2/16/2011
Suffers
• Note that even though Clara broke her arm again, the primary key is unique
Your Individual Project
31CIS 5365 Entity Relationship Diagrams
• Our ERD so far:
Physician• PhysID
LastName
FirstName
Street
City
State
Zipcode
Specialty
Patient• PatID
LastName
FirstName
x Address
~ Physician
Suffers• ~ PatID
• ~ IllCode
• DateSeen
Illness• IllCode
Description
Treats
1 .. * 1 .. * * .. 1
Attribute Notation:• Primary Key~ Foreign Keyx Composite
AttributeAside from using UML, what is different here????
Why is the relationship between Patient-Suffers-Illness 1..* - *..1??
Your Individual Project
32CIS 5365 Entity Relationship Diagrams
• As we have seen, we CAN NOT deal with M:M relationships:
Patient• PatID
LastName
FirstName
x Address
~ Physician
• Initially we had:Illness• IllCode
Description
Suffers
* .. *
• We found out that we could not deal with this situation unless we broke it into an Associative entity:
Patient• PatID
x Address
~ Physician
x Name
Suffers• ~ PatID
• ~ IllCode
• DateSeen
Illness• IllCode
Description
1 .. * * .. 1
Your Individual Project
33CIS 5365 Entity Relationship Diagrams
• When we consider this relationship:Patient• PatID
x Address
~ Physician
x Name
Suffers• ~ PatID
• ~ IllCode
• DateSeen
Illness• IllCode
Description
1 .. * * .. 1
• We should note that it is one we know how to deal with:• In a 1:M relationship, the foreign key goes on the side of the many:
Patient• PatID
x Address
~ Physician
x Name
Suffers• ~ PatID
• ~ IllCode
• DateSeen
1 M
PatID can occur only once in Patient, but many times in Suffers
M
Illness• IllCode
Description
1
IllCode can occur many times in Suffers, but only once in Illness
Your Individual Project
34CIS 5365 Entity Relationship Diagrams
• The actual Tables might appear as:PatID Last First Street City State Physician
255356278 Sotomayor Sonya 12 Oregon El Paso TX 456789012399872889 Bush W 123 Mesa El Paso TX 234567890589021099 Mubarack Hosni 18 Hideout El Paso TX 345678901620896798 Martinez Susana 7 Mayor St Anthony NM 567890123730927457 Lohan Lindsay 12 Necklace El Paso TX 456789012
PatID IllCode DateSeen399872889 C879013 1/18/2009730927457 B348701 2/8/2011589021099 D404678 2/10/2011399872889 B667180 4/19/2010730927457 B348701 7/17/2010730927457 B667180 10/23/2010255356278 A896507 9/29/2009
IllCode DescriptionA507762 Broken HeartA896507 Broken Left FootB348701 Sticky FingersB667180 Bad HairC879013 AmnesiaD404678 Wounded EgoF750191 Headache
• We Now Know:• Sonya Sotomayor suffered from:
• A broken left foot on 2/29/2009• W Bush suffered from:
• Amnesia on 1/19/2009• Bad Hair on 4/19/2010
• Hosni Mubarak suffered from:• A Wounded Ego on 2/10/2011
• Linsay Lohan suffered from:• Sticky Fingers on 7/17/2010• Sticky Fingers (again) on 2/8/2011• Bad Hair on 10/23/2010
Your Individual Project
35CIS 5365 Entity Relationship Diagrams
• 3rd Relationship:
Illness Requires Drugs
Given 1 Illness, how many Drugs?Mandatory?
Given 1 Drug, how many Illnesses?Mandatory?
• We already know how this one will come out
We already know that this means that Requires will become an Associative Entity
Your Individual Project
36CIS 5365 Entity Relationship Diagrams
• 3rd Relationship:• The ERD can be rewritten as:
Illness• IllCode
Description
1 .. * * .. 1Requires• IllCode
• DrugCode
• DateGiven
Number
Drugs• Drugcode
Name
X Others
Do we need DateGiven???
Your Individual Project
37CIS 5365 Entity Relationship Diagrams
• 3rd Relationship:• I think we have a problem!!!• Let’s look at the tables we might generate:
IllCode DescriptionA507762 Broken HeartA896507 Broken Left FootB348701 Sticky FingersC879013 AmnesiaF750191 Bad Hair
IllCodeDrugCode DateGiven No
B348701 27891101 8/19/2009 23C879013 1033456712/16/2009 90F750191 53372820 2/23/2010 60B348701 10334567 4/13/2010 20B348701 5337282010/20/2009 60A507762 72234695 3/14/2011 150B348701 1033456712/23/2010 30A896507 33890112 1/27/2010 45
DrugCode Name10334567 Thorazine12337690 Aspirin27891101 Placebo27781018 Retin-A33890112 Codeine45399034 Ibuprofin53372820 Laughing Gas72234695 Vitamin A
Illness Requires Drugs
• All we know is:• A Broken Heart has been treated with Vitamin A • A Broken Left Foot has been treated with Codeine• Sticky Fingers has been treated with Thorazine, Retin-A, Laughing Gas & Codeine• Bad Hair has been treated with a Placebo
SO???
Your Individual Project
38CIS 5365 Entity Relationship Diagrams
• 3rd Relationship:• Let’s consider our old friend Lindsay Lohan
PatID Last First Street City State Physician730927457 Lohan Lindsay 12 Necklace El Paso TX 345678901
PatID IllCode DateSeen730927457 B348701 2/8/2011730927457 B348701 7/17/2010730927457 F750191 10/23/2010
IllCode DescriptionB348701 Sticky FingersF750191 Bad Hair
IllCode DrugCode DateGivenB348701 27891101 8/19/2009B348701 53372820 10/20/2009B348701 33890112 12/23/2010F750191 27891101 6/19/2010
DrugCode Name10334567 Thorazine27891101 Placebo33890112 Codeine53372820 Laughing Gas72234695 Vitamin A
Patient
Suffers Illness
Require Drugs
• We know Lindsay suffers from Sticky Fingers, and that sticky fingers have been treated using Thorazine, Codeine, Laughing Gas, and Vitamin A
Which ones were given to Lindsay???
Your Individual Project
39CIS 5365 Entity Relationship Diagrams
• 4th Relationship:• We could try and create a relationship between patient and drug
Patient Suffers Illness
Require
DrugsIs Given
Given one Patient, how many Drugs?Mandatory?
Given one Drug, how many Patients?Mandatory?
Your Individual Project
40CIS 5365 Entity Relationship Diagrams
• 4th Relationship:• The tables might appear as:
Patient• PatID
x Address
~ Physician
x Name
Suffers• ~ PatID
• ~ IllCode
• DateSeen
Illness• IllCode
Description
1 .. * * .. 1
Requires• IllCode
• DrugCode
• DateGiven
Number
Drugs• Drugcode
Name
~ PatID
1 *
* 1
1
*
Seems Messy!!• 5 Tables• 5 Relationships• PatId and IllCode each used
in 3 different Tables
All to link a Patient with an Illness and a
Drug???
Your Individual Project
41CIS 5365 Entity Relationship Diagrams
• Let’s think this through• Can we have a patient who doesn’t have an illness?• Can we have a patient who need any drugs?• Can there be an illness that is not associated with any
Patient?• Can there be a illness that is not associated with any
Drug?• Can there be a Drug that is not associated with any
Patient?• Can there be a Drug that is not associated with any
Illness?
The three entities are Interrelated
Your Individual Project
42CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship
Treatment
Patient
DrugIllness
• We know the three entities involved:• Let’s call the relationship between them Treatment
• Given 1 Patient and 1 Illness, how many Drugs? Many• Given 1 Patient and 1 Drug, how many Illnesses? Many• Given 1 Illness and 1 Drug, how many Patients? Many
A M:M:M ternary relationship
Your Individual Project
43CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• Let’s look at some of the attributes required:
Patient• PatID
x Address
~ Physician
x Name
Illness• IllCode
Description
Drugs• Drugcode
Name
~ PatID
Treatment• ~ PatID
• ~ DrugCode
• ~ IllCode
Note that these have NOT changed
* .. 1* .. 1
* 1
Houston, we have a problem!!!
Your Individual Project
44CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• Just as we did in the Associative Entity Suffers, We could
add a Time Stamp (to make the primary key unique): Treatment• ~ PatID
• ~ DrugCode
• ~ IllCode
• TDate
Instead of 4-concatenated keys, could we add a single auto-numbered Key?
• Yes --• Having a single primary is always nice
Treatment
~ PatID
~ DrugCode
~ IllCode
TDate
• TreatID
• BUT --• We still have to make sure that a patient treatment is NOT entered
twice
Your Individual Project
45CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• Let’s see how the Tables might appear:
PatID Last First Street City State Physician255356278 Sotomayor Sonya 12 Oregon El Paso TX 456789012399872889 Bush W 123 Mesa El Paso TX 234567890589021099 Mubarack Hosni 18 Hideout El Paso TX 345678901620896798 Martinez Susana 7 Mayor St Anthony NM 456789012730927457 Lohan Lindsay 12 Necklace El Paso TX 345678901
IllCode DescriptionA507762 Broken HeartA896507 Broken Left FootB348701 Sticky FingersB667180 Bad HairC879013 AmnesiaD102234 Wounded EgoF750191 Headache
DrugCode Name10334567 Thorazine12337690 Aspirin27891101 Placebo27781018 Retin-A33890112 Codeine45399034 Ibuprofin53372820 Laughing Gas72234695 Vitamin A
PatID IllCode DrugCode TDate399872889 C879013 53372820 1/19/2009730927457 B348701 72234695 6/20/2009730927457 B667180 27781018 4/15/2010399872889 B667180 27891101 5/1/2010255356278 A507762 10334567 6/10/2010620896798 F750191 12337690 7/16/2010255356278 F750191 27891101 12/6/2010730927457 B348701 33890112 2/8/2010589021099 D102234 53372820 2/10/2011589021099 F750191 10334567 2/10/2011
Illness Treatment Drugs
Patient
How would this work?
Your Individual Project
46CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• Let’s pick on poor Lindsay any more; Let’s pick on poor W.
PatID Last First Street City State Physician399872889 Bush W 123 Mesa El Paso TX 234567890
IllCode DescriptionB667180 Bad HairC879013 Amnesia
DrugCode Name27891101 Placebo53372820 Laughing Gas
PatID IllCode DrugCode TDate399872889 C879013 53372820 1/19/2009399872889 B667180 27891101 5/1/2010
Illness Treatment Drugs
Patient
Is this an improvement over our previous model??
• On January 19, 2009 W. suffered Amnesia and was given Laughing Gas
• On May 1, 2010 suffered Bad Hair and was given a Placebo
Your Individual Project
47CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• We know that we eliminated two relationships (Suffers and
Requires) and replaced them with one (Treatment).• Let’s look at the size of the old model:
Field: PatID Last First Street City State PhysicianSize (Bytes): 9 15 10 25 20 2 9
Patient
Total: 90 bytesIllness
Field: IllCode DescriptionSize (Bytes): 8 25
Total: 33 bytes
DrugsField: DrugCode NameSize (Bytes): 9 25 Total: 34 bytes
157 bytesThe size of these tables remain unchanged.
Field: PatID IllCode DateSeenSize (Bytes): 9 8 10
SuffersTotal: 27 bytes
RequiresField: IllCode DrugCode DateGivenSize (Bytes): 8 9 10
Total: 27 bytes 54 bytes
Your Individual Project
48CIS 5365 Entity Relationship Diagrams
• Developing a Ternary relationship• Let’s look at the size of the New model:
• We know that Tables Patient, Illness, and Drugs will remain unchanged.
• The only change will be in the size of the Associative Entities
Field: PatID IllCode DrugCode TDateSize (Bytes): 9 8 9 10
• Size of Old Model Associative Entities: 54 bytes
• Size of New Model Associative Entity: 36 bytes
• A savings of only 18 bytes per record, But:• A saving of one Table• A Substantial saving in Metadata• A large savings if we have a large number of records:
• If we have 100,000 records, we save 1,800,000 Bytes• Occam’s Razor: "entities must not be multiplied beyond
necessity"
Your Individual Project
49CIS 5365 Entity Relationship Diagrams
• We have only one more relationship left:“You work for a hospital. The Head Administrator has told you
that he suspects that Dr. Smith, as well as all of the other physicians which she supervises, has been pre-scribing too much Codeine for their patients.”
• We have seen this type of relationship before:
Physician Supervises
Your Individual Project
50CIS 5365 Entity Relationship Diagrams
• We have only one more relationship left:• Let’s see how the Table might appear:
Physician• PhysID
LastName
FirstName
Street
City
State
Zipcode
Specialty
~ Supervisor
PhyID Last First Street City St Specialty Super.234567890 Kervorkian Jack 32 Viscount El Paso TX Euthanasia345678901 Zhivago Yuri 19 Redd Rd El Paso TX Cardiology 456789012456789012 Rebenneck Mac 65 Piano St. La Union NM Orthopedics567890123 Love Strange 7 Rio St, El Paso TX Psychiatry 234567890678901234 McGraw Phil 12 S.R. 123 Canutio NM Oprahology 234567890
• Dr. Jack Kervorkian Supervises
• Dr. Mac Rebenneck Supervises
• Dr. Strange Love• Dr. Phil McGraw
• Dr. Yuri Zhivago
Your Individual Project
51CIS 5365 Entity Relationship Diagrams
• We have only one more relationship left:• Let’s see how the Table might appear:
Physician• PhysID
LastName
FirstName
Street
City
State
Zipcode
Specialty
~ Supervisor
PhyID Last First Street City St Specialty Super.234567890 Kervorkian Jack 32 Viscount El Paso TX Euthanasia345678901 Zhivago Yuri 19 Redd Rd El Paso TX Cardiology 456789012456789012 Rebenneck Mac 65 Piano St. La Union NM Orthopedics567890123 Love Strange 7 Rio St, El Paso TX Psychiatry 234567890678901234 McGraw Phil 12 S.R. 123 Canutio NM Oprahology 234567890
• Dr. Jack Kervorkian Supervises
• Dr. Mac Rebenneck Supervises
• Dr. Strange Love• Dr. Phil McGraw
• Dr. Yuri Zhivago
CIS 5365 Entity Relationship Diagrams 52
Our Final ERD
Supervises Physician Treats
Patient
TreatmentIllness Drugs
CIS 5365 Entity Relationship Diagrams 53
Our Final ERD (Using UML)
Physician• PhysID
LastName
FirstName
Street
City
State
Zipcode
Specialty
~ Supervisor
Patient• PatID
x Address
~ Physician
x Name
Illness• IllCode
Description
Drugs• Drugcode
Name
~ PatID
Treatment• ~ PatID
• ~ DrugCode
• ~ IllCode
• TDate
1
*
1
**
1
1
*
CIS 5365 Entity Relationship Diagrams 54
Any Questions??