You are on page 1of 47

The Entity-Relationship Model { E-R MODEL }

DBMS by Er. K.S.Dhindsa

Overview

Database Design: The E-R Model Entities


Attributes Relationships
DBMS by Er. K.S.Dhindsa

Overview

Data Model:
A set of concepts to describe the structure of a database, and certain constraints that the database should obey

DBMS by Er. K.S.Dhindsa

Schemas versus Instances

Database Schema: The description of a database. Includes descriptions of the database structure and the constraints that should hold on the database. Schema Diagram: A diagrammatic display of (some aspects of) a database schema. Schema Construct: A component of the schema or an object within the schema, e.g., STUDENT, COURSE. Database Instance: The actual data stored in a database at a particular moment in time. Also called database state (or occurrence).
DBMS by Er. K.S.Dhindsa

Example ER Diagram

DBMS by Er. K.S.Dhindsa

FIGURE 2.1 Schema diagram for the database

DBMS by Er. K.S.Dhindsa

Database Design
External View

Pilot
(Order Entry)

Engineer
(A/C Receivable)

Passenger
(Inventory)

Conceptual Model (ERD)

General Design
(Comprehensive Data Model)

Logical Model (Relational)

Blueprint
(Database Schema)

Physical Reality (DBMS)

Aircraft (Database)
DBMS by Er. K.S.Dhindsa

The Entity Relationship Diagram


An E-R diagram is a graphical representation of an organizations data Such data includes the people, places, objects, events, or concepts (along with their characteristics and relationships) that are relevant to an organization

DBMS by Er. K.S.Dhindsa

Entities
Person, place, object, event, or concept about which the organization wishes to collect and maintain data Nouns are used to describe entities Examples: Employee, Student, Nurse City, State, Country Sale, Registration, Account Entity Type versus Entity Instance

DBMS by Er. K.S.Dhindsa

Types of Entities
Strong Entity: can exist independently EMPLOYEE

Weak Entity: cannot exist without the owner entity (with which it has an identifying relationship) Has a primary key that is derived from the owner entity in the relationship

EMPLOYEE

DEPENDENT

has
DBMS by Er. K.S.Dhindsa

Attributes
Properties or characteristics of entities (or relationships) Provide the actual data that describe entities (or relationships)
EMPLOYEE

E_ID E_Name E_Address


DBMS by Er. K.S.Dhindsa

Unique Attributes
Candidate keys are ALL attributes that uniquely define an instance of an entity

A primary key is the candidate key that is chosen as the most unique of them all!

DBMS by Er. K.S.Dhindsa

Composite Attributes
Attributes that are not atomic (or simple), i.e., those attributes that can (and need to) be broken down further
EMPLOYEE

E_ID E_Name E_Address (E_Street,


E_City, E-Zip)
DBMS by Er. K.S.Dhindsa

Multi-valued Attributes

Some attributes may have multiple values ...


EMPLOYEE {E_Skill}

but they may need to be fixed before proceeding


EMPLOYEE has SKILL

S_Code S_Name
DBMS by Er. K.S.Dhindsa

Derived Attributes
Those attributes whose values can be calculated from the values of other attributes (either in the database or in the system) Value is not stored in the database (since it does not take up any space) E.g., Age can be calculated, where date-of-birth is stored

DBMS by Er. K.S.Dhindsa

Relationships
Refer to the associations (or links) between entities Use verbs to describe the links May have attributes (in some cases) Are directional

STUDENT

Lives in

DORMITORY

EMPLOYEE

Works in

STORE
DBMS by Er. K.S.Dhindsa

Associative Entities
A (many-to-many) relationship that is better represented as an entity because it: contains attributes from the entities it links and has its own attributes

CUSTOMER

Orders

PRODUCT

CUSTOMER

ORDER

PRODUCT
DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


ER model forms the basis of an ER diagram

ERD represents the conceptual database as viewed by end user Main Components Entities In E-R models an entity refers to the entity set. An entity is represented by a rectangle containing the entitys name.
Attributes Attributes are represented by ovals and are connected to the entity with a line. Each oval contains the name of the attribute it represents. Attributes have a domain -- the attributes set of possible values. Attributes may share a domain. Relationships
DBMS by Er. K.S.Dhindsa

The Attributes of the STUDENT Entity

DBMS by Er. K.S.Dhindsa

Primary Keys Underlined in the ER diagram

Key attributes are also underlined in frequently used table structure shorthand
Ideally composed of only a single attribute Possible to use a composite key: Primary key composed of more than one attribute

DBMS by Er. K.S.Dhindsa

Purpose of E-R Model

Facilitates database design Express logical properties of mini-world of interest within enterprise - Universe of Discourse Conceptual level model Not limited to any particular DBMS E-R diagrams used as design tools A semantic model captures meanings

DBMS by Er. K.S.Dhindsa

Symbols used in E-R Diagram

Entity rectangle Attribute oval Relationship diamond Link - line

DBMS by Er. K.S.Dhindsa

E-R Diagram descript ion


Student: stuId, lastName, firstName, major, credits
Each student has a unique id and has at most one major

Department: deptCode, deptName, office


Each department has a unique code and a unique name, and that each department ahs one office designated as the departmental office

Faculty: facId, lastName, firstName, rank


facId is unique and that every faculty member must belong to department. One faculty member in each department is the chairperson.

Class: classNumber, sched, room


classNumber consists of deptCode, courseNumber, section

Textb ook: isbn, author, title, publisher


A book can have multiple authors

Evaluation: date, rater, rating


Evaluation is a weak entity, dependent on Faculty
DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


Classes of Attributes

A simple attribute cannot be subdivided. Examples: Age, Sex, and Marital status A composite attribute can be further subdivided to yield additional attributes.
Examples:

ADDRESS Street, City, State, Zip PHONE NUMBER Area code, Exchange number

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


Classes of Attributes A single-valued attribute can have only a single value. Examples: A person can have only one social security number. A manufactured part can have only one serial number.
Multivalued attributes can have many values. Examples: A person may have several college degrees. A household may have several phones with different numbers Multivalued attributes are shown by a double line connecting to the entity.

DBMS by Er. K.S.Dhindsa

Multivalued attributes in an Entity

DBMS by Er. K.S.Dhindsa

Splitting the Multivalued Attribute into New Attributes

DBMS by Er. K.S.Dhindsa

A New Entity Set Composed of Multivalued Attributes Components

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model

A derived attribute may be calculated (derived) from other attributes Need not be physically stored within the database Can be derived by using an algorithm
Example: AGE can be derived from the data of birth and the current date.

DBMS by Er. K.S.Dhindsa

Depiction of a Derived Attribute

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


Relationships A relationship is an association between entities. Relationships are represented by diamondshaped symbols.

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


Connectivity The term connectivity is used to describe the relationship classification (e.g., one-to-one, one-to-many, and many-tomany).

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model

Cardinality Cardinality expresses the specific number of entity occurrences associated with one occurrence of the related entity. The minimum and maximum number of entity occurrences

DBMS by Er. K.S.Dhindsa

Connectivity and Cardinality in an ERD

DBMS by Er. K.S.Dhindsa

Entity Relationship Models

Mandatory Relationships Optional Relationships Many-to-Many Relationships One-to-Many Relationships One-to-One Relationships Recursive Relationships

DBMS by Er. K.S.Dhindsa

Mandatory, Many-to-Many

INSTRUCTOR

STUDENT

INSTRUCTOR

STUDENT

DBMS by Er. K.S.Dhindsa

Optional, Many-to-Many

DEPARTMENT

STUDENT

DEPARTMENT

STUDENT

DBMS by Er. K.S.Dhindsa

Optional/Mandatory, Many-to-Many

INSTRUCTOR

SKILL

INSTRUCTOR

SKILL

DBMS by Er. K.S.Dhindsa

Optional/Mandatory, One-to-Many

PRODUCT

VENDOR

PRODUCT

VENDOR

DBMS by Er. K.S.Dhindsa

Mandatory, One-to-One

AUTOMOBILE

ENGINE

AUTOMOBILE

ENGINE

DBMS by Er. K.S.Dhindsa

Recursive

EMPLOYEE

supervises

is supervised by

DBMS by Er. K.S.Dhindsa

Entity Relationship Models

Mandatory Relationships Optional Relationships Many-to-Many Relationships One-to-Many Relationships One-to-One Relationships Recursive Relationships

DBMS by Er. K.S.Dhindsa

A Comparison of ER Modeling Symbols

DBMS by Er. K.S.Dhindsa

SUMMARY

DBMS by Er. K.S.Dhindsa

A Generalization Hierarchy with Overlapping Subtypes

Overlapping relationships are indicated by Gs

DBMS by Er. K.S.Dhindsa

The Entity Relationship (E-R) Model


Multivalued Attribute in Relational DBMS The relational DBMS cannot implement multivalued attributes. Possible courses of action for the designer Within the original entity, create several new attributes, one for each of the original multivalued attributes components ( Figure 4.4). Create a new entity composed of the original multivalued attributes components ( Figure 4.5).

DBMS by Er. K.S.Dhindsa

The Entity-Relationship Model { E-R MODEL }

Er. Kanwalvir Singh Dhindsa Department of CSE & IT

DBMS by Er. K.S.Dhindsa

You might also like