You are on page 1of 56

Entity Relationship Diagram

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

diagram

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.

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.

Entity Sets
Departments Professors Students Administrators

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

Relationship
Students and Professors are under a certain department Admin manage the campus/ departments

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

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 varchar OrderDate datetime Table Items ID int Primary Key Desc varchar

weak.... Table OrderDetail OrderID 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.

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 attends/ enrolls SCHOOL

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.

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.

circle ( ) indicates that the relationship is optionalthe 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 mandatorythe 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.

A A A A

B B B B

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

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:

Each school enrolls at least zero and at most many students

STUDENT

Each student attends at least one and at most one

SCHOOL

school

One-to-one (1:1)

Man
One-to-many (1:n)

Woman

Customer
Many-to-many (n:m)

Order

Course

Subject

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

Degrees of relationship, alternative representation


One-to-one (1:1)

Man
One-to-many (1:n)

Woman

Customer
Many-to-many (n:m)

Order

Course

Subject

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

Person

Car

A person must own at least one car. A car doesnt have to be owned by a person, but if it 1 is, it is owned by at least one person. A person may own many cars.
optional relationship mandatory relationship

Student

Course

Subject

A Student Record Entity Diagram

Mandatory

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

INSTRUCTOR

STUDENT

INSTRUCTOR

STUDENT

DEPARTMENT

STUDENT

DEPARTMENT

STUDENT

INSTRUCTOR

SKILL

INSTRUCTOR

SKILL

An

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

EMPLOYEE

CLIENT

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 clients salesperson may or may not be the same employee as the clients customer service representative; each relationship is treated independently.

PRODUCT

VENDOR

PRODUCT

VENDOR

AUTOMOBILE

ENGINE

AUTOMOBILE

ENGINE

EMPLOYEE

supervises

is supervised by

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 persons father will be recorded in the system, so the relationship is modeled as optional).

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 VEHICLE MODEL

PART

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.

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.

PRISON

CONVICT PAROLE OFFICER

The

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

Many-to-many

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

SALES ORDERS

INV. ITEMS

SALES ORDERS

ORDER ITEMS

INV. ITEMS

CUSTOMERS

CLERKS

SALES ORDERS

ORDER ITEMS

INV. ITEMS

Key attribute
A 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 attribute
A multivalued attribute can have more than one value. For example, an employee entity can have multiple skill values.

Derived attribute

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

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-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.

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

Identify

the entities. Determine all significant interactions. Analyze the nature of the interactions. Draw the ERD.

More Examples

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.

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 C Set F to 32+(9 C/5) Print the value of C , F Stop

Payroll System Flowchart

You might also like