1/30/2005 1 IST 210 Entity-Relationship Model & Diagram Todd S. Bacastow IST 210: Organization of data
1/30/2005 1
IST 210 Entity-Relationship Model & Diagram
Todd S. BacastowIST 210: Organization of data
1/30/2005 2
IST 210 Design Principles
The client has some vague idea of what he/she wants. YOUR task is to design a DB that represents these thoughts and onlythese thoughts.
1/30/2005 3
IST 210 Data ModelingData modeling is a formalismEntity-Relationship Model (ER) Entity Relationship model:
a visual model attempts to capture the structure of data
1/30/2005 4
IST 210 What is Visual Modeling?
Business Process
Order
Item
Ship via
Computer System
Visual Modeling is modeling using standard graphical notations
1/30/2005 5
IST 210 Visual Modeling is a Communication Tool
Use visual modeling to capture business objects and logic
Use visual modeling to analyze and design your database
Copyright © 1997 by Rational Software Corporation
1/30/2005 6
IST 210 Entity-Relationship (E-R) Modeling
Premises The real world consists of entitiesEntities in one enterprise are relatedDatabase model = relevant entities + relationships among them
Entities and relationships have attributes
1/30/2005 7
IST 210 E-RFeatures
Relatively easy to model real-world Translates easily to relational data model
Basic ConceptsEntity sets Relationship sets Attributes
1/30/2005 8
IST 210 EntitiesDefinition
Entityan object that is distinguishable from other objects.
a particular student, a particular book
Entity seta set of entities of the same type that share the same set of properties
students, books
1/30/2005 9
IST 210 EntitiesExamples of these entity types are:
Person: employeestudentcustomersupplier
1/30/2005 10
IST 210 Entity TypesPlace:
citystatecounty
Object: vehiclebuildingairplaneanimal
1/30/2005 11
IST 210 Entity TypesEvent:
purchasesaleregistrationgame
Concept: accountcoursework groupdepartment
1/30/2005 12
IST 210 Weak EntitiesWeak entities are entities, but with a difference---Weak entities only exist because some other entity exists. For example:
two entities employee and salary-historysalary-history is a weak entity the record of an employee’s salary history could only exist if a record of an employee also existsE.g., Joe Smith’s salary history wouldn’t make much sense if Joe Smith doesn’t exist in the data base.
1/30/2005 13
IST 210 Finding EntitiesEntities are normally located through the various user views identified during analysisSearch for entities by:
looking for nounsfinding objects/things that have many instances (i.e., things stored in tables) have descriptive/defining properties (attributes)
1/30/2005 14
IST 210 AttributesDefinition:
Attribute: a descriptive property possessed by all members of an entity set. Attribute set: the set of all attributes possessed by members of an entity set.
e.g., book = (author,title,publisher,barcode, etc.) e.g., student = (ID,surname,firstname,course, etc.) e.g., subject = (code,name,lecturer,timetable, etc.)
1/30/2005 15
IST 210 AttributesProperties of Attributes
Domain - the seat of permitted values for each attribute Type:
data type simple vs. composite attributes single-valued vs. multivaluedderived vs. stored
1/30/2005 16
IST 210 Simple & Composite AttributesSimple attributes cannot be decomposed without loss of meaning, e.g.,
Title: Mr., Ms., Mrs., Dr.
Composite attributes can be further decomposed without loss of meaning, e.g.,
Name: first name + last nameDate: day + month + yearAddress: street + city + state + zip
1/30/2005 17
IST 210 Single-Valued AttributesSingle-valued attributes occur once only for each entity instance, e.g.
IDNameDepartment
1/30/2005 18
IST 210 Multi-Valued AttributesMulti-valued attributes can occur more than once for the same entity instance; e.g.
Sports person playsHobbies person likesSkills person has achievedCourses person has takenDegrees person completed
1/30/2005 19
IST 210 Stored & Derived AttributesA derived attribute is one that can be calculated from other stored data
not usually stored as an attribute occasionally stored to speed information/query requests when these occur frequently
Maybe shown on ERD as attribute name within a dashed-line ellipse
1/30/2005 20
IST 210 RelationshipsRelationship: an association among 2 or more entities
E1: student - R: takes - E2: subject e.g. Sara Smith takes IST210
1/30/2005 21
IST 210 Relationship setsRelationship set: a relation among entity sets:
e.g. (Smith,IST210) takesRelationship sets
have degree may have attributes e.g. final mark attribute for takesrelationship
1/30/2005 22
IST 210 E-R DiagramEntity
Relationship
1/30/2005 23
IST 210 Entity Relationship Diagram Symbols
The symbols used in an ERD are not standardised so -
diagrams may appear somewhat different depending upon who created themsymbols used for our purposes will follow the format
1/30/2005 24
IST 210 Graphical Elements of the ER Diagram
Its components are: rectangles representing entity sets. ellipses representing attributes. diamonds representing relationship sets.
Relationship
• Customer Account
Entity
• Customers• Accounts
Attribute
• id• name
1/30/2005 25
IST 210 Basic Symbols
1/30/2005 26
IST 210 Relationship
STUDENT COURSETake
Connect two or more entity setsRepresented by diamondsThink of the “value” of a relationship set as a tableOne row for each list of entities, one from each set, that are connected by the relationship
1/30/2005 27
IST 210 Finding RelationshipsOften represented by a Verballows answers to questions not available through individual entity types
DEPENDENTHasEMPLOYEE
Weak Entity
1/30/2005 28
IST 210 Attributes & RelationshipsRelationship can have 1 or more attributes
depend on relationshipdo not belong to the entitiesfor example the date on which a course was completed belongs to the relationship rather than either of the participating entitiesshown in same way as entity attributes
1/30/2005 29
IST 210 Multiplicity or Cardinality
1/30/2005 30
IST 210 Cardinality Symbology
1/30/2005 31
IST 210 One-to-One
1/30/2005 32
IST 210 One-to-Many
1/30/2005 33
IST 210 Many-to-Many
1/30/2005 34
IST 210 Recursive
1/30/2005 35
IST 210 Common ConstraintsKeys we will discuss nextSingle-value constraints must have a certain value
Null valueReferential integrity constraints “broken link to a web page”Domain constraints a negative account balanceGeneral constraints limits you set
1/30/2005 36
IST 210 Keys
Primary key Foreign key Primary key
1 Wood Bob C Ist 357
2 Kent Chuck B Ist 115
3 Smith Jane A Ist 357
4 Boone Dan B Ist 357
ID Last First Grade Class
Student
Ist 357 48 Jones
Ist 115 120 Brower
Ist 20 120 Mennis
Name #Stud Instructor
Class
1/30/2005 37
IST 210 KeysA key is a set of attributes whose values can belong to at most one entityIn E-R model, every E.S. must have a keyMore than one key: a set of attributes is the “designated” keyIn E-R diagrams: underline all attributed of the designated key
1/30/2005 38
IST 210 A Multi-attribute Key
dept+number (e.g. IST 210) form a key for courses.Possibly, hours+room also forms a key. But we have not designated it as such.
1/30/2005 39
IST 210 Weak Entities & KeysWeak entity sets:
Does not have a primary keyare meaningful only in the context of a relationship with an owning strong entity set
1/30/2005 40
IST 210 We Made it!