Download - Entityrelationshipmodel
![Page 1: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/1.jpg)
.
Enes BOLFİDAN
Ahmet Fahri KILIÇ
diagram
![Page 2: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/2.jpg)
Topics
• Design Process
• Modeling
• Constraints
• E-R Diagram
• Design Issues
• Weak Entity Sets
• Extended E-R Features
![Page 3: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/3.jpg)
DATAunorganized
form
ex: student’s score
![Page 4: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/4.jpg)
Informationprocessed, structured and
organized data
ex: class average which can be calculated from data.
![Page 5: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/5.jpg)
TABLE
A table is a collection (rows) of dataon a single related topic.
![Page 6: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/6.jpg)
Difference between table and database
Table Database
A table is an object inside a database
A database has tables of data,
a table is a collection (rows) of data on a single related topic.
A database can have 10 or thousands of tables
Ex: employee tableContains only employees detail. But it not contains inventory detail.
But DB is a collection of Employee table as well as inventory table.
![Page 7: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/7.jpg)
Sample Table
![Page 8: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/8.jpg)
Sample Database DB is a
collection related tables
![Page 9: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/9.jpg)
Why we need ER diagram
giving you image of how the tablesshould connect
what fields are going to be on eachtable
the tables connection, if many-to-many, one-to-many.
“ER diagrams are easy for non-technicalpeople to understand, and thus aretypically used by database designersbefore the schema ever exists”
![Page 10: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/10.jpg)
Entity
• An entity can be defined as anything, which can be uniquely identified and about which data is stored in a database.
• Entity: Real-world object distinguishable from otherobjects. An entity is described using a set of attributes.
Employees
ssnname
![Page 11: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/11.jpg)
Examples of entities
– Person: EMPLOYEE, STUDENT, PATIENT
– Place: STORE, WAREHOUSE
– Object: MACHINE, PRODUCT, CAR
– Concept: ACCOUNT, COURSE
![Page 12: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/12.jpg)
Entity Relationship(ER) Modelling
• In 1976, Peter Chen first proposed modeling databases using a graphical technique that humans can relate easily.
• An Entity–Relationship (ER) model is an abstract or conceptual way of describing a database
• The goal of E-R Modelling is to produce a model of data that is non-technical and free of ambiguities
![Page 13: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/13.jpg)
Entity set
• Entity Set: A collection of similar entities.E.g., all employees.– All entities in an entity set have the same set of
attributes.
![Page 14: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/14.jpg)
Person, place, object, event or concept about which data is to be maintained
named property or characteristic of an entity
Association between the instances of one or more entity types
EntityName Verb Phrase AttributeName
Example
![Page 15: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/15.jpg)
RELATIONSHIP
• Relationship: Association among two ormore entities. e.g., rose works in Pharmacydepartment.
• Relationship Set: Collection of similarrelationships.
• Same entity set could participate in differentrelationship sets, or in different “roles” in same set.
![Page 16: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/16.jpg)
Relationship Example
Associations between instances of one or more entity types that is of
interest
Buying is the relationship between Vendor and Customer.
Author Book
Relationship name: writes
An author writes one or more booksA book can be written by one or more authors.
![Page 17: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/17.jpg)
ER Diagram Notation
Represents an entity set
Represents an attribute
Represent linking of attributes to entity sets and of entity sets to relationship sets.
Represents a relationship
![Page 18: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/18.jpg)
Draw ER Diagram in MS-Visio
![Page 19: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/19.jpg)
Degree of Relationships
• Degree: number of entity types that participate in a relationship
• Three cases
– Unary: between two instances of one entity type
– Binary: between the instances of two entity types
![Page 20: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/20.jpg)
• Ternary: among the instances of three entity types
![Page 21: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/21.jpg)
Attributes
• Example of entity types and associated attributes:
STUDENT: Student_ID, Student_Name, Home_Address, Phone_Number,
Major
![Page 22: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/22.jpg)
Attribute types
1.Single-valued attribute
2.Multi-valued attribute
3.Simple Attribute
4.Composite Attribute
5.Key Attribute
6.Derived Attribute
![Page 23: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/23.jpg)
1. Single-valued attribute : Attribute that holds a single value for an occurrence of an entity type. E.g. age, first_name, last_name, full_name, etc.
2 Multi-valued attribute :Attribute where there might be more than one value for a given occurrence of an entity type.
Full Name
Age
Phonenumber
Student
![Page 24: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/24.jpg)
3. Simple Attribute: It is composed of a single component e.g. age, first_name, last_name, etc. But full_name is not simple attribute. Because it is composed of first_name and last_name.
4. Composite Attribute: It is composed of more than one component.
5. Key Attribute:
• Primary Key is a key attribute.
• At most one attribute in each entity
![Page 25: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/25.jpg)
6. Derived Attribute : The value of the derived attribute can be derived from the values of other related attributes. Age of a person can be derived from the date of birth and current date.
i.e. age = current date –date of birth. In this example, age is the derived attribute.
![Page 26: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/26.jpg)
Multiplicity
![Page 27: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/27.jpg)
Mapping Cardinality Constraints
• Express the number of entities to which anotherentity can be associated via a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mappingcardinality must be one of the following types:– One to one
– One to many
– Many to one
– Many to many
![Page 28: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/28.jpg)
Mapping Cardinalities
One to one One to many
Note: Some elements in A and B may not be mapped to any elements in the other set
![Page 29: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/29.jpg)
Mapping Cardinalities
Many to one Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set
![Page 30: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/30.jpg)
KEY• Key and key attributes:
– Key: a unique value for an entity– Key attributes: a group of one or more attributes that uniquely
identify an entity in the entity set• Super key, candidate key, and primary key
– Super key: a set of attributes that allows to identify and entity uniquely in the entity set
– Candidate key: minimal super key• There can be many candidate keys
– Primary key: a candidate key chosen by the designer• Denoted by underlining in ER attributes.
![Page 31: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/31.jpg)
Key Constraints
• Consider Works_In: An employee can work in manydepartments; a dept can have many employees.
• In contrast, each dept has at most one manager,according to the key constraint on Manages.
![Page 32: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/32.jpg)
Weak Entity Sets• An entity set that does not have a primary key is
referred to as a weak entity set.
• The existence of a weak entity set depends onthe existence of a identifying entity set
– it must relate to the identifying entity setvia a total, one-to-many relationship setfrom the identifying to the weak entity set
– Identifying relationship depicted using adouble diamond
![Page 33: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/33.jpg)
• In a relational database, a Weak Entity is an entity that cannot beuniquely identified by its attributes alone; therefore, it must usea foreign key in conjunction with its attributes to create a primarykey. The foreign key is typically a primary key of an entity it isrelated to.
• Strong entity and Weak entity : Weak entity is an entity thatdepends on another entity. Weak entity doesn't have key attributeof their own.
![Page 34: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/34.jpg)
Entity-Relationship (ER) Diagram
• ER Modeling is a “top-down” approach to databasedesign.
• Entity Relationship (ER) Diagram
– A detailed, “logical representation” of the entities,associations and data elements for an organization orbusiness
Notation uses three main constructs
– Data entities
– Relationships
– Attributes
![Page 35: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/35.jpg)
E-R Diagrams
Rectangles represent entity sets.
Diamonds represent relationship sets.
Lines link attributes to entity sets and entity sets to relationship sets.
Ellipses represent attributes
Double ellipses represent multivalued attributes.
Dashed ellipses denote derived attributes.
Underline indicates primary key attributes (will study later)
![Page 36: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/36.jpg)
E-R Diagram With Composite, Multivalued, and Derived Attributes
![Page 37: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/37.jpg)
Relationship Sets with Attributes
![Page 38: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/38.jpg)
Roles• Entity sets of a relationship need not be distinct• The labels “manager” and “worker” are called roles; they
specify how employee entities interact via the works_forrelationship set.
• Roles are indicated in E-R diagrams by labeling the lines thatconnect diamonds to rectangles.
• Role labels are optional, and are used to clarify semantics of therelationship
![Page 39: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/39.jpg)
Cardinality and Connectivity
• Relationships can be classified as either
• one – to – one
• one – to – many
• many – to –many
• Cardinality : minimum and maximum number ofinstances of Entity B that can (or must be) associatedwith each instance of entity A.
Connectivity
![Page 40: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/40.jpg)
Cardinality Constraints• We express cardinality constraints by drawing
either a directed line (), signifying “one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.
• One-to-one relationship:– A customer is associated with at most one loan via
the relationship borrower
– A loan is associated with at most one customer via borrower
![Page 41: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/41.jpg)
One-To-Many Relationship
• In the one-to-many relationship a loan isassociated with at most one customer viaborrower, a customer is associated withseveral (including 0) loans via borrower
![Page 42: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/42.jpg)
Many-To-One Relationships• In a many-to-one relationship a loan is
associated with several (including 0)customers via borrower, a customer isassociated with at most one loan via borrower
![Page 43: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/43.jpg)
Many-To-Many Relationship• A customer is associated with several (possibly
0) loans via borrower• A loan is associated with several (possibly 0)
customers via borrower
![Page 44: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/44.jpg)
Connectivity
• Chen Model
– 1 to represent one.
– M to represent many
• Crow’s Foot
many
One
One or many
1
M
Mandatory one , means (1,1)
![Page 45: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/45.jpg)
Binary Relationships
• 1:M relationship
– Relational modeling ideal
– Should be the norm in any relational database design
The 1: M relationship between PAINTER and PAINTING
![Page 46: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/46.jpg)
Binary Relationships
• 1:1 relationship
– Should be rare in any relational database design
– A single entity instance in one entity class isrelated to a single entity instance in anotherentity class
– Could indicate that two entities actually belongin the same table
![Page 47: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/47.jpg)
The 1:1 Relationship Between PROFESSOR and DEPARTMENT
![Page 48: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/48.jpg)
Binary Relationships
• M:N relationships
– Must be avoided because they lead to data redundancies.
– Can be implemented by breaking it up to produce a set of 1:M
relationships
– Can avoid problems inherent to M:N relationship by creating a
composite entity or bridge entity
• This will be used to link the tables that were originally
related in a M:N relationship
• The composite entity structure includes-as foreign keys-at
least the primary keys of the tables that are to be linked.
![Page 49: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/49.jpg)
The M:N Relationship Between STUDENT and CLASS
This CANNOT be implemented as shown next…..
Bowser
Smithson
Accounting 1 (ACCT-211)
Intro to Microcomputing (CIS-220)
Intro to Statistics (QM-261)
![Page 50: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/50.jpg)
Changing the M:N relationship to TWO 1:M relationships
![Page 51: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/51.jpg)
Extended E-R
• Specialization
• Generalization
• Aggregation
![Page 52: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/52.jpg)
Specialization• Top-down design process: we designate sub
groupings within an entity set that aredistinctive from other entities in the set.
• These sub groupings become lower-level entitysets that have attributes or participate inrelationships that do not apply to the higher-level entity set.
• Depicted by a “triangle component labeled ISA”• Attribute inheritance – a lower-level entity set
inherits all the attributes and relationshipparticipation of the higher-level entity set towhich it is linked.
![Page 53: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/53.jpg)
Specialization Example
![Page 54: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/54.jpg)
Generalization• A bottom-up design process – combine a number of entity
sets that share the same features into a higher-level entityset.
• Specialization and generalization are simple inversions ofeach other; they are represented in an E-R diagram in thesame way.
• The terms specialization and generalization are usedinterchangeably.
![Page 55: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/55.jpg)
Specialization and Generalization (Cont.)
• Can have multiple specializations of an entityset based on different features.
• E.g. permanent_employee vs.temporary_employee, in addition to officer vs.secretary vs. teller
• Each particular employee would be– a member of one of permanent_employee or
temporary_employee,– and also a member of one of officer, secretary, or
teller
• The ISA relationship also referred to as“superclass – subclass” relationship
![Page 56: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/56.jpg)
Design Constraints on a Specialization/Generalization
• Constraint on which entities can be members of a given lower-level entity set.– Condition-defined : evaluated by an explicit condition or
predicate.– User-defined : database user assigns
• Constraint on whether or not entities may belong to more than one lower-level entity set within a single generalization.– Disjoint
• An entity can belong to only one lower-level entity set• Noted in E-R diagram by writing disjoint next to the ISA triangle
– Overlapping• an entity can belong to more than one lower-level entity set
![Page 57: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/57.jpg)
Design Constraints on a Specialization/Generalization (Contd.)
• Completeness constraint
– Total : an entity must belong to one of thelower-level entity sets
– Partial : an entity need not belong to one of thelower-level entity sets
![Page 58: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/58.jpg)
Aggregation
Consider the ternary relationship works-on, which we saw earlier
Suppose we want to record managers for tasks performed by an employee at a branch
![Page 59: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/59.jpg)
Aggregation (Cont.)• Relationship sets works_on and manages represent
overlapping information– Every manages relationship corresponds to a works_on
relationship– However, some works_on relationships may not correspond to
any manages relationships • So we can’t discard the works_on relationship
• Eliminate this redundancy via aggregation– Treat relationship as an abstract entity– Allows relationships between relationships – Abstraction of relationship into new entity
• Without introducing redundancy, the following diagram represents:– An employee works on a particular job at a particular branch – An employee, branch, job combination may have an associated
manager
![Page 60: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/60.jpg)
Aggregation (Cont.)
• Relationship sets works-on and managesrepresent overlapping information
– Every manages relationship corresponds to a works-on relationship
– However, some works-on relationships may notcorrespond to any manages relationships wecan’t discard the works-on relationship
• Redundancy problem aggregation
![Page 61: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/61.jpg)
E-R Diagram With Aggregation
![Page 62: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/62.jpg)
Summary of Symbols Used in E-R Notation
![Page 63: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/63.jpg)
Summary of Symbols (Cont.)
![Page 64: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/64.jpg)
Alternative E-R Notations
![Page 65: Entityrelationshipmodel](https://reader030.vdocument.in/reader030/viewer/2022032421/55a709981a28ab260b8b468d/html5/thumbnails/65.jpg)
References
http://www.smartdraw.com/resources/tutorials/entity-relationship-diagrams/http://www.tutorialspoint.com/dbms/er_diagram_representation.htmhttp://www-db.in.tum.de/~grust/teaching/ss06/DBfA/db1-04.pdfhttp://s3.amazonaws.com/ppt-download/entity-relationship-diagram2http://www.cse.unt.edu/~huangyan/5350/Slides/ER.ppthttp://en.wikipedia.org/wiki/Entity%E2%80%93relationship_modelhttp://databases.about.com/cs/specificproducts/g/er.htm