ER Diagrams
-
Upload
arthur-pierce -
Category
Documents
-
view
72 -
download
3
description
Transcript of ER Diagrams
![Page 1: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/1.jpg)
ER DiagramsCMSC 461Michael Wilson
![Page 2: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/2.jpg)
Entity-relationship diagramming (ER Diagrams) ER Diagrams are diagrams that can
describe relations/databases Meant to be high level Pure concept, no implementation Can help you figure out how to design
your relations, choose keys, etc. We’re going to be using Chen diagrams
Keep this in mind when looking up info on the internet
![Page 3: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/3.jpg)
Why devote an entire lecture to a diagramming method? You can use ER Diagrams to help design
your data Choose keys, figure out where to put
what attributes Handy for trying to picture what you’re
really trying to model
![Page 4: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/4.jpg)
ExampleRecord ID PatientNa
meDate of Visit
Diagnosis
14233 Mario Mario 04/28/1991 Leg injury174342 Snow Villiers 12/05/2012 Brain damage189232 Lara Croft 12/05/2012 Powder burns
![Page 5: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/5.jpg)
ER Diagram
![Page 6: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/6.jpg)
ER Diagram Diagram of an earlier relation
Square box is an “entity” Ovals are “attributes”
Entities can be related to one another We can use ER Diagrams to show the
relationship between two entities Diamonds can show a relationship type
![Page 7: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/7.jpg)
Primary keys
![Page 8: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/8.jpg)
Primary keys Primary keys can be shown by
underlining a particular attribute
![Page 9: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/9.jpg)
Multivalued attributes
![Page 10: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/10.jpg)
Multivalued attributes Attributes with multiple values are
shown using concentric ovals A multivalued attribute is an attribute that
consists of multiple other attributes or values
For example patient name: First name Last name
![Page 11: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/11.jpg)
Relationships between entities These relationships are high level as well
They simply describe, at a conceptual level, how the two entities relate to one another
Relationships are generally plaintext words or sentences Customer places orders Bands have members Programmers develop video games
Relationships are not necessarily between two entities – can be between more
![Page 12: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/12.jpg)
Relationships and cardinality
![Page 13: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/13.jpg)
Cardinality Different “sides” of the relationship can
have differing cardinalities Four different types of cardinalities here:
1 to 1 1 to many Many to 1 Many to many
![Page 14: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/14.jpg)
Cardinality Describing cardinality
One patient can have many patient diagnoses
We represent this by putting a “1” on the side of the relationship attached to Patient and an “N” on the side of the relationship attached to patient records
![Page 15: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/15.jpg)
Weak entities
![Page 16: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/16.jpg)
Weak entities A weak entity is an entity that depends on
another entity to exist In this case, a patient’s insurance info must be
attached to a patient Therefore, it must reference a patient, and is a
weak entity, represented by a double rectangle This relationship is described as an identifying
relationship, represented by a double diamond Tuples cannot be uniquely identified by attributes
alone Has to have a foreign key
![Page 17: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/17.jpg)
Funky relationships?!
![Page 18: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/18.jpg)
Self referential relationships Employees report to a manager, who is
also an employee Therefore, the relationship in fact
references itself This is totally kosher
![Page 19: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/19.jpg)
Ternary relationships
![Page 20: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/20.jpg)
Ternary relationships Here, an employee can sell multiple
games to a customer These are also valid
Can sometimes reduce ternary relationships into binary relationships as well These are probably closer to how they
would be laid out in your DBMS
![Page 21: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/21.jpg)
Ternary relationships
![Page 22: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/22.jpg)
Really frustrating thing about diagramming This applies to more than just ER
diagrams, but diagramming in general There isn’t really one way to do it
If you do some research and find examples, you’ll see a billion different ways
In general, stay consistent in your meanings, define them if you’re unsure
Crow’s foot notation
![Page 23: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/23.jpg)
Crow’s foot notation
![Page 24: ER Diagrams](https://reader030.fdocuments.us/reader030/viewer/2022020117/5681301d550346895d959bd3/html5/thumbnails/24.jpg)
ER Diagram Links https://drive.draw.io/
Drawing tool (more than just ER diagrams)
http://creately.com/blog/diagrams/er-diagrams-tutorial/
http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model Wikipedia’s page is very good