Introduction to ERD

Preview:

Citation preview

DATA MODELINGEntity Relationship Diagram

LINK TO ERD INTRODUCTION

http://www.studytonight.com/dbms/er-diagram

WHAT IS ERD ER-Diagram is a visual representation of data that

describes how data is related to each other.

An entity-relationship diagram is a data modeling technique that creates a graphical representation of the entities, and the relationships between entities, within an information system. Entity is described using a noun.

The Entity-Relationship (ER) model, a high-level data model that is useful in developing a conceptual design for a database.

Peter Chen developed ERDs in 1976. Since then Charles Bachman and James Martin have added some sligh refinements to the basic ERD principles.

ER diagrams often use symbols to represent three different types of information. Boxes are commonly used to represent entities. Diamonds are normally used to represent relationships and ovals are used to represent attributes.

COMPONENTS OF ERD The entity is a person, object, place or event for which data is collected. For

example, if you consider the information system for a business, entities would include not only customers, but the customer's address, and orders as well. The entity is represented by a rectangle and labelled with a singular noun.

The relationship is the interaction between the entities. In the example above, the customer places an order, so the word "places" defines the relationship between that instance of a customer and the order or orders that they place. A relationship may be represented by a diamond shape, or more simply, by the line connecting the entities. In either case, verbs are used to label the relationships.

The cardinality defines the relationship between the entities in terms of numbers. An entity may be optional: for example, a sales rep could have no customers or could have one or many customers; or mandatory: for example, there must be at least one product listed in an order. There are several different types of cardinality notation; crow's foot notation, used here, is a common one. In crow's foot notation, a single bar indicates one, a double bar indicates one and only one (for example, a single instance of a product can only be stored in one warehouse), a circle indicates zero, and a crow's foot indicates many. The three main cardinal relationships are: one-to-one, expressed as 1:1; one-to-many, expressed as 1:M; and many-to-many, expressed as M:N.

The attributes is the property associated with an entity. For eg. If customer is an entity attributes are custno, custname,address, contact no etc.

EXAMPLE OF ELEMENTS OF E-R MODEL

Entity SetsDepartmentsProfessorsStudentsAdministrators

AttributesName of Departments, Phone No., Address...Name, SSN, Address of Professors...

RelationshipStudents and Professors are under a certain

departmentAdmin manage the campus/ departments

ENTITY An entity is an object or concept about

which you want to store information. An entity is a business object that

represents a group, or category of data.”1

Each entity is represented by a box within the ERD. Entities are abstract concepts, each representing one or more instances of the concept in question. An entity might be considered a container that holds all of the instances of a particular thing in a system.

STUDENT SCHOOL

Course

TYPES OF ENTITY Strong Entity Weak Entity An entity set that does not possess sufficient attributes to form a primary key is called

a weak entity set. One that does have a primary key is called a strong entity set. For example,

Strong entity...Table Orders ID        int      Primary Key OrderNum  varcharOrderDate datetime

Table ItemsID        int      Primary KeyDesc      varchar

weak....Table OrderDetailOrderID   int      Foreign Key (references Order.ID)ItemID    int      Foreign Key (references Item.ID)Qty       int

In this example the items and orders tables are core level or "Stong" entities.  They stand alone without requiring other defined objects.The Order detail is a "Weak" entity as it requires the existence of both an order and item to exist.

RELATIONSHIP Relationships are represented by lines

between entities. Relationship lines indicate that each instance of an entity may have a relationship with instances of the connected entity, and vice versa.

Relationship is described using a verb

STUDENT SCHOOL

The diagram above now indicates that students may have some relationship with schools. More specifically, there may be a relationship between a particular student (an instance of the student entity) and a particular school (an instance of the school entity).

If necessary, a relationship line may be labeled to define the relationship. In this case, one can infer that a student may attend a school, or that a school may enroll students. But if necessary, this relationship could be labeled for clarification:

STUDENT SCHOOLattends/enrolls

Read the first relationship definition, “attends,” when tracing the relationship left to right or top to bottom. Read the second definition, “enrolls,” when tracing the relationship right to left or bottom to top.

CARDINALITY/OPTIONALITY Symbols at the ends of the relationship

lines indicate the optionality and the cardinality of each relationship. “Optionality” expresses whether the relationship is optional or mandatory. “Cardinality” expresses the maximum number of relationships.

 

A circle ( ) indicates that the relationship is optional—the minimum number of relationships between each instance of the first entity and instances of the related entity is zero. One can think of the circle as a zero, or a letter O for “optional.”

A stroke ( | ) indicates that the relationship is mandatory—the minimum number of relationships between each instance of the first entity and instances of the related entity is one.

 The second symbol indicates cardinality. A stroke ( | ) indicates that the maximum number of relationships is one. A “crows-foot” ( ) indicates that many such relationships between instances of the related entities might exist.

THE FOLLOWING DIAGRAM INDICATES ALL OF THE POSSIBLE COMBINATIONS:

A

A

A

A

B

B

B

B

Each instance of A is related to a minimum ofzero and a maximum of one instance of B

Each instance of B is related to a minimum ofone and a maximum of one instance of A

Each instance of A is related to a minimum ofone and a maximum of many instances of B

Each instance of B is related to a minimum ofzero and a maximum of many instances of A

SCHOOL

STUDENTEach school enrolls

at least zero

and at most many

students

Each student attends

at least one

and at most one

school

In our model, we wish to indicate that each school may enroll many students, or may not enroll any students at all. We also wish to indicate that each student attends exactly one school. The following diagram indicates this optionality and cardinality:

DEGREES OF A RELATIONSHIP

Man Woman

Customer

Order

Course Subject

One-to-one (1:1)

One-to-many (1:n)

Many-to-many (n:m)

NOTE: Every many to many relationship consists of two one to many relationships working in opposite directions

1 M

1 1

M M

Degrees of relationship, alternative representation

Man Woman

Customer

Order

Course Subject

One-to-one (1:1)

One-to-many (1:n)

Many-to-many (n:m)

NOTE: Every many to many relationship consists of two one to many relationships working in opposite directions

A person must own at least one car. A car doesn’t have to be owned by a person, but if it is, it is owned by at least one person. A person may own many cars.

NOTATION FOR OPTIONAL ATTRIBUTES

CarPerson

mandatory relationshipoptional relationship

1 M

1

A SAMPLE ER DIAGRAM

Student

A Student Record Entity Diagram

Course Subject

ENTITY RELATIONSHIP MODELS Mandatory Relationships Optional Relationships Many-to-Many Relationships One-to-Many Relationships One-to-One Relationships Recursive Relationships

MANDATORY, MANY-TO-MANY

INSTRUCTOR STUDENT

INSTRUCTOR STUDENT

OPTIONAL, MANY-TO-MANY

DEPARTMENT STUDENT

DEPARTMENT STUDENT

OPTIONAL/MANDATORY,MANY-TO-MANY

INSTRUCTOR SKILL

INSTRUCTOR SKILL

MULTIPLE RELATIONSHIPS BETWEEN ENTITIES An entity may have multiple relationships

with another entity. These are depicted in the ERD with multiple relationship lines connecting the two entities

EMPLOYEE CLIENT

salesperson

customer service rep

The diagram above indicates that an employee may be the salesperson assigned to zero or many clients, and an employee may be the customer service representative for zero or many clients. Each client has exactly one salesperson and exactly one customer service representative. Each client’s salesperson may or may not be the same employee as the client’s customer service representative; each relationship is treated independently.

OPTIONAL/MANDATORY,ONE-TO-MANY

PRODUCT VENDOR

PRODUCT VENDOR

MANDATORY, ONE-TO-ONE

AUTOMOBILE ENGINE

AUTOMOBILE ENGINE

RECURSIVE

EMPLOYEEsupervises

is supervised by

RECURSIVE RELATIONSHIP

In some cases, entities can be self-linked. For example, employees can supervise other employees.

Recursive Relationships Instances of entities may have relationships with other instances of the same entity. These relationships may be drawn with relationship lines that begin and end connected to the same entity. Common occurrences of these recursive relationships include parent/child relationships:

PERSON

father of/child of

The diagram above indicates that a person may be the father of zero or many persons, and that a person may have zero or one father. (Not every person’s father will be recorded in the system, so the relationship is modeled as optional).

ENTITY SUBTYPES There are times when it is convenient to

depict relationships that apply to an entire class of things, as well as depict relationships that apply only to certain types of the larger class. Entity subtypes accommodate these relationship depictions. In the ERD, entity subtypes may be depicted by entity boxes shown within larger entity boxes. The large entity represents the class or supertype, and the smaller boxes depict the subtypes.

INVENTORY

PART

VEHICLE MODEL

MFG.LOCATION

The example above depicts an “inventory” entity, with the subtypes of “vehicle” and “part.” A vehicle has one or many parts, and every part is associated with one and only one kind of vehicle (according to this diagram, there are no interchangeable components). All items in inventory, whether they are vehicles or parts, have a manufacturing location, but only vehicles are of a particular model.

EXCLUSIVE-OR RELATIONSHIP

If an entity instance may have either one relationship or another, but not both, the constraint may be modeled with an exclusive-or relationship, represented as a tree with a solid dot where the tree branches.

The following diagram indicates that each convict is assigned to a prison, or to a parole officer, but not both:

 

CONVICT

PRISON

PAROLEOFFICER

RESOLVING MANY-TO-MANY RELATIONSHIPS Many-to-many relationships should be

avoided. We can resolve a many-to-many relationship by dividing it into two one-to-many relationships.

RESOLVING MANY-TO-MANY RELATIONSHIPS

SALES ORDERS INV. ITEMS

SALES ORDERS INV. ITEMSORDER ITEMS

EXAMPLE (ER DIAGRAM)

SALES ORDERS

INV. ITEMSORDER ITEMS

CLERKSCUSTOMERS

ATTRIBUTE

TYPES OF ATTRIBUTESKey attributeA key attribute is the unique, distinguishing characteristic of the entity. For example, an employee's social security number might be the employee's key attribute.

Multivalued attributeA multivalued attribute can have more than one value. For example, an employee entity can have multiple skill values.

Derived attributeA derived attribute is based on another attribute. For example, an employee's monthly salary is based on the employee's annual salary.

KEY IN THE E/R MODEL Superkey is a set of one or more attributes that,

taken collectively, for us to identify uniquely an item in the entity set. For example, customer-id is a superkey.

Candidate key is a minimal superkey. For example, customer-name and customer-street is sufficient to distinguish among members of the customer entity set. Then {customer-name, customer-street } is a candidate key.

Primary key denotes a candidate key that is chosen by the database designer as the principal means of identifying items within an entity set. the primary key should be chosen such that its attributes are never, or very rarely, changed. For example, Social-security numbers are guaranteed to never changed.

SINGLE/MULTI-VALUED ATTRIBUTES Single-valued attributes are

attributes that only have a single value for a particular entity.

Multi-valued attributes refers to items that are not singled-value and Null valued. For example, consider an employee entity set with the attribute phone-number. An employee may have zero, one, or several phone numbers; different employee may have different numbers of phones.

A simple attribute is one component that is atomic. A composite attribute has multiple components, each of which is atomic or composite

ER diagram notation for composite attribute domain, name

STEPS INVOLVED IN CREATING AN ERD Identify the entities. Determine all significant interactions. Analyze the nature of the interactions. Draw the ERD.

More Examples

WHAT IS FLOWCHART A flow chart is a graphical or symbolic

representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the process flow direction.

A NOTE ON FLOWCHART SYMBOLS Different flow chart symbols have different meanings. The

most common flow chart symbols are: Terminator: An oval flow chart shape indicating the start or

end of the process. Process: A rectangular flow chart shape indicating a normal

process flow step. Decision: A diamond flow chart shape indication a branch in

the process flow. Connector: A small, labeled, circular flow chart shape used to

indicate a jump in the process flow. Data: A parallelogram that indicates data input or output (I/O)

for a process. Document: used to indicate a document or report (see image

in sample flow chart below).

Flowchart to convert temperature given in centigrade to Fahrenheit. The system flowchart for the following algorithm: Prompt the user for the centigrade temperature.Store the value in CSet F to 32+(9´ C/5)Print the value of C , FStop

Payroll System Flowchart

Recommended