Vous êtes sur la page 1sur 35

Chapter 2

Entity Relationship Model (ER Model)


Muddassar Ali International University of Technology Twintech (IUTT) Yemen muddassar.pieas@gmail.com

E-R Model Concepts

The ER model describes data as:


Entities Attributes Relationships between entities

The overall logical structure of a database can be expressed graphically by ER diagram.

Muddassar Ali

Entity symbols

Relationship symbols

Attribute symbols A special entity that is also a relationship

Relationship cardinalities specify how many of each entity type is allowed

Relationship degrees specify number of entity types involved

Muddassar Ali

Entities

An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event, plant etc Entities have attributes An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees etc.

Muddassar Ali

Attributes
Attribute - property or characteristic of an entity type Example: COURSE entity has attributes

Course code Course Title Course Description Number of Credits

Classifications of attributes:

Required versus Optional Attributes Simple versus Composite Attribute Single-Valued versus Multi-valued Attribute Stored versus Derived Attributes
Muddassar Ali 5

Required versus Optional Attributes

Required attribute is that which is must for an entity it must not be null. Optional is not necessary for an entity it may be null.

Muddassar Ali

Simple versus Composite Attribute


Simple attribute is atomic and cannot be further divided They describe simple features of an entity

Example: Title for the COURSE entity type Age for EMPLOYEE entity type

Composite attributes Can be divided into smaller subparts


Example: Address may consists of StreetAddress, City, State, ZipCode, Country
Muddassar Ali 7

A composite attribute

Muddassar Ali

Single-Valued versus Multi-valued Attribute

Single Valued attributes have only one value for each entity of an entity set Each attribute Age and/or Sex has single value for each EMPLOYEE entity Example: Single-valued: Gender = M Multi-valued attributes Example: Phone attribute may be multivalued when person has several phones (home, office, mobile)

Have a set of values for a particular entity

Muddassar Ali

Stored versus Derived Attributes


Derived Attributes are functionally related to existing attribute(s) that are stored and can be calculated from that other attributes values Example: Age of an EMPLOYEE can be calculated from his/her Birth date

Muddassar Ali

10

Key Attributes
Key attribute is one or more attributes that uniquely identifies each entity of the entity set Value of key attribute

Identifies each entity uniquely Must be distinct for each entity in the entity set Unique for every extension of the entity type

A key attribute has its name underlined inside the oval

Muddassar Ali

11

Simple key attribute

The key is underlined

Muddassar Ali

12

Composite key attribute

The key is composed of two subparts


Muddassar Ali 13

Entity with a multivalued attribute (Skill) and derived attribute (Years_Employed)

Primary Key

Multivalued:
Derived from date employed and current date
Muddassar Ali

an employee can have more than one skill


14

Relationships

A Relationship Type is an association among two or more entity types


Name of relationship must be Verb phrase Relationships can have attributes These describe features pertaining to the association between the entities in the relationship

Examples Employee Manages Departments Student Studies Course


Muddassar Ali 15

Degree of Relationships

Degree of a relationship is the number of entity types that participate in it Unary Relationship : 1 entity involved Binary Relationship : 2 entities involved Ternary Relationship : 3 entities involved N-ary Relationship : n-entities involved
Muddassar Ali 16

Degree of relationships

One entity related to another of the same entity type

Entities of two different types related to each other

Entities of three different types related to each other


17

Muddassar Ali

Cardinality of Relationships

One-to-One Each entity in the relationship will have exactly one related entity One-to-Many An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity Many-to-Many Entities on both sides of the relationship can have many related entities on the other side

Muddassar Ali

18

Cardinality Constraints

Cardinality Constraints - the number of instances of one entity that can or must be associated with each instance of another entity Minimum Cardinality

If zero, then optional If one or more, then mandatory The maximum number

Maximum Cardinality

Muddassar Ali

19

Muddassar Ali

20

Muddassar Ali

21

Note: a relationship can have attributes of its own


Muddassar Ali 22

Basic relationship with only maximum cardinalities

Mandatory minimum cardinalities

Muddassar Ali

23

Optional cardinalities with unary degree, one-to-one relationship

Muddassar Ali

24

Muddassar Ali

25

Entities can be related to one another in more than one way

Muddassar Ali

26

Here max cardinality constraint is 4

Muddassar Ali

27

Strong vs. Weak Entities, and Identifying Relationships

Strong entities exist independently of other types of entities has its own unique identifier represented with single-line rectangle Weak entity dependent on a strong entitycannot exist on its own does not have a unique identifier represented with double-line rectangle Identifying relationship links strong entities to weak entities represented with double line diamond
Muddassar Ali 28

Strong entity

Identifying relationship
Muddassar Ali

Weak entity
29

Associative Entities

entity it has attributes AND its a relationship it links entities together


Its an When should a relationship with attributes instead be an associative entity? All relationships for the associative entity should be many. The associative entity could have meaning independent of the other entities and preferably has a unique identifier. It should also have other attributes. The associative entity may participate in other relationships independent of the entities related in the associated relationship. Ternary relationships should be converted to associative entities
Muddassar Ali 30

An associative entity (CERTIFICATE)

Associative entity involves a rectangle with a diamond inside. Note that the many-to-many cardinality symbols face toward the associative entity and not toward the other entities
Muddassar Ali 31

Sample E-R Diagram

Muddassar Ali

32

Explanation of E-R diagram


1)
2) 3) 4) 5) 6)

Customer Submits zero or many Orders but Order must be submitted by one customer. Order Request one or many Products But Product can be Requested by zero or many Orders. Item is Used_In one or many Products And Product Used one or many Items. Supplier supplied zero or many Items but item may be supplied by one or many suppliers. An item is included by zero or many shipments and shipment includes one or many items. one supplier sends zero or many shipments but shipment is send by exactly one supplier.
Muddassar Ali 33

E-R diagram for Pine Valley Furniture

Muddassar Ali

34

THE END

Any Questions???

Muddassar Ali

Vous aimerez peut-être aussi