Vous êtes sur la page 1sur 11

2002, Learning Campus

THE ENTITY RELATIONSHIP DIAGRAM (ERD)


Now that you understand data, information and databases, we can move on to learning about the entity relationship diagram. The ER modeling approach remains the mainstream approach for conceptual data modeling. The contextual level data model is detailed by developing the ERD, which is most often used as a tool for communications between database designers. The ER model is used to construct a conceptual data model, which is a representation of the structure and constraints of a database. The entity relationship diagram is a graphical representation of that data and information and how they relate to each other. Data modeling is the most important part of the system development process because: 1. The characteristics of data are crucial. 2. Data rather than processes are the most complex. 3. Data tend to be more stable than the business processes. The ERD can also be defined as a detailed, logical representation of the data for an organization or for a business. The ERD is expressed in terms of: 1. Entities 2. Relationships 3. Attributes 4. Cardinalities Entities Entity is an object that can be identified in the users work environment. Entities can be tangible for example like a pen, or intangible like a purchase order. Entities of a given type are grouped into an entity class. For example: students, professors, courses, etc. An instance of an entity class is the representation of a particular entity. For example: student John Doe, ID # 12345 is an instance of the students entity class. Entities are pictured in boxes. Symbol: A rectangular box with the name of the entity written inside. Entity Name . . Examples (entity names): ? CUSTOMER ? ITEM ? PRODUCT ? SUPPLIER

2002, Learning Campus

? ORDER ? SHIPMENT All of the examples provide information on a companies transaction processing and sales system. Name: Notice that usually an entity describing the information that we need to store and track is a NOUN.

Relationship Symbol: A diamond with the name of the relationship written inside of it.

Relationship Name

Examples (relationship names): ? Customer PLACES order ? Company SUBMITS a bid ? University SENDS a PO ? Student REGISTERS for course ? Instructor GIVES a course ? Name: Notice that usually an entity describing the information that we need to store and track is a VERB. Entities are associa ted with one another through relationships, which can include many entities. The number of entities in the relationship is the degree of Relationships between two items are most common and are called binary relationships . A relationship between three entities is called a ternary relationship. If four or more entities participate in a relationship we call it an n-ary relationship. There are three types of binary relationships. One-to-one relationship One-to-one relationship exists when a single entity of one type is related to another single entity of another type. Example: Assume that for a large car assembly plant each supplier produces one specific item (for example one produces tires, another produces seats etc) and doesnt produce anything else. This is a one-to-one relationship that relates a single entity item to a

2002, Learning Campus

single entity supplier. This means that no item can have more than one supplier, and no supplier has more than one item. Connecting two entities by a straight line depicts the one-to-one relationship. Another method of connecting two entities is by portraying the relationships with diamonds. In the diamond we describe the character of the relationship (e.g. supplier produces the item). In general an ERD can be read in any directio n. For example, if we read the diagram above from left to right it would be read as: supplier produces item, and if its read from right to left it would be read as follows: item is produced by supplier. One-to-many relationship exists when a single entity of one type is related to many entities of another type. Example: Assume that customers place orders to purchase compact disks in on-line music store. In this situation each customer can place many different orders; however, each order is unique, and can be placed only by one single customer. Thus, we have a one-tomany relationship that relates one entity customer to many orders. One-to-many relationship is depicted by connecting two entities with a straight line and placing a chicken foot at the many side. Many-to- many relationship exists when many entities of one type are related to many entities of another type. For example: Assume once again that customers place orders to purchase compact disks in on-line music store. Each compact disk can be listed in many orders, and each order can contain many different compact disks. Hence, here we have a many-to-many relationship that relates many orders to many compact disks. Many-to- many relationships are depicted by connecting two entities with a straight line and placing a chicken foot at both many sides. A binary many-to- many relationship requires a correlation table. A correlation table is the intermediary between two entities that have a many-to- many relationship. In conclusion, an ERD represents the conceptual design of a database. To formulate an ERD one must first analyze the problem he is encountering. Then he must identify the entities and attributes, and finally draw an ERD using the appropriate symbols. Attributes Entities ha ve attributes, or properties, that describe the entities characteristics. For example: each student has a student ID, last name and first name, date of birth, etc. Each entity must have at least two attributes. One of which is the primary key (unique identifier), while the other attribute must provide additional facts about the entity. The attributes of each entity are listed beside the entity. Entity instances have identifiers - attributes that identify entity instances. Identifiers that uniquely identify the entity instances are called primary keys. For example: a student ID number, which is unique for each student. On an ERD, primary keys must be underlined. Other identifiers, that identify the entity instance but not with complete accuracy, are

2002, Learning Campus

called secondary keys. For example: a students last name can identify a student, but it is not unique for this student because other students can have the same last name. Symbol: An attribute is a word representing the data written in the entity rectangular box. The first attribute is the key attribute, which is the unique key identifier for the data. This is usually an ID number such as the SIN, and student number. Entity Name Attribute Key Attribute 2 Attribute 3 Attribute n Examples (Attributes): Consider the entity customer. The attributes would be: ? CustmerID (Primary key attribute) ? CustNameLast ? CustoNameFirst ? CustGenter ? CustAddress ? CustDateOfBirth ? CustShippingAddress ? CustBillingAddress ? Etc. Name: Notice that usually an attribute describing the data type that we need to store and track is a NOUN. Cardinalities Symbol: The cardinality of a relationship identifies the way the instances of the entity are associated with each other. Cardinalities also represent business rules. The cardinalities are specified on both sides of the relationship shown below. Cardinalities are usually written on top of the line.

Cardinality

Relationship Name

Cardinality

Examples (relationship names):

2002, Learning Campus

? ? ? ? ? ?

1 N which implies many P which implies many Q which implies many M which implies many Any letter of the alphabet which implies many

2002, Learning Campus

The Degree of a Relationship The degree of a relationship is the number of entity types that participate in the relationship. Please specify what type of a relationship are the following and why (12 points):

Individual N

Is Related to

Recursive: Entity related to itself.

Client

Make

M Purchases

Binary: Two entities related to each other.

Firm

Signs Q Contract

Contractor

Ternary: Three entities are involved in the relationship.

2002, Learning Campus

The Type of a Relationship There are three types of relationships: 1. 1 to 1 2. 1 to many 3. Many to many

Employee

has

Parking

A 1 to 1 Relationship

An employee can have only one parking space

Customer

Place

Orders

A 1 to many Relationship

A customer can place many orders

Student

Register

Courses

A many to many Relationship

A student can register to many courses and a course can be registered by many students

2002, Learning Campus

Consider the following ERD Problem Statement of Problem:


Each semester, each student must be assigned an advisor who counsels students about degree requirements and helps students register for courses. We track the advisor by ID, name and internal phone number. We track the student by ID and name and major. For a course, we need the course name & ID. A. Represent the situation with an ERD. B. During registration, if the assigned advisor is not available, another advis or can register the student. We need to track the advisor, student and courses. Modify your original ERD to account for the new requirement. Solution procedure: Step 1: Break down paragraph into small sentences. Each semester, each student must be assigned an advisor who counsels students about degree requirements and helps students register for courses. We track the advisor by ID, name and internal phone number. We track the student by ID and name and major. For a course, we need the course name & ID. Paragraph a can be further decomposed to two parts: Each semester, each student must be assigned an advisor who counsels students about degree requirements and helps students register for courses. i. Each semester, each student must be assigned an advisor who counsels students about degree requirements ii. An advisor helps students register for the courses. Step 2: Identify the ENTITIES. a. b. c. Student (from a) Advisor (from a) Courses (from a) Step 3: Identify Attributes. Do not forget to show Primary keys Relationships Cardinalities Step 4: Complete drawing with all details.

a. b. c. d.

a.

a. b. c.

2002, Learning Campus

SOLUTION

A) Develop the conceptual data model for this problem which is needed to store all information and data mentioned in the problem and; B) With respect to the above CDM you have developed, please answer the following questions: 1) How many entities does the CDM include? 2) What are the entities (Give names only)? 3) What are the business rules? 4) How are the rules translated into cardinalities and relationships? 5) What assumptions have you taken that affect your data model?

A)
Student

Registers

courses

Prereqs

Graduate Student

B) (1) There are five entities, two of which are associative. (2) -Student -Graduate student -Courses -Registers (associative entity) -Prerequisites (associative entity)

2002, Learning Campus

(3-4)Business rules and their translation in cardinalities and relationships:

Student

M
registers

Courses

Courses

M
Prereqs

N
One student can register to many classes; One course can be taken by many students. One course can have many prerequisites; One prerequisite can lead to many courses.

M
Student registers registers

N
Courses

1
Graduate Student (advisor) One student can get help from one graduate student; One graduate student can help many students.

1
Graduate Student (Advisor) One grad student can register many courses; Many courses can be registered by one advisor.

(5)Assumptions: - Although students must register for at least two classes, this does not affect the CDM; - A course can have more than one prerequisite; - Student can register with any advisor and is not assigned a unique advisor. Scenario where Assumption #3 is changed to where student IS assigned an advisor:

Student

Registers

Courses

Prereqs

M
is assigned 1

1 Graduat e student
(advisor)

10

2002, Learning Campus

PROBLEMS

1.

Buy It Now is an exciting optional enhancement to your listings. As a seller, if you choose to use the Buy It Now feature at the time of listing, you will be able to name a price at which you would be willing to sell your item to any buyer who meets your specified price. Your listing will be run as a normal auction, but will now feature a Buy It Now price. Buyers will have the option to buy your item instantly without waiting for the listing to end or can bid on your item as us ual. Buyers, if you see a Buy It Now item, you'll need to act quickly! Buy It Now will only be available before the first bid (or the first bid high enough to meet or beat the seller's reserve in Reserve Price auctions) is placed on the item. As soon as a bid is placed, the Buy It Now price will no longer be available and the item will sell through the normal process. DEVELOP THE DATA MODEL FOR THE AUCTION BUSINESS AT EBAY.

SUPERTYPE, SUBTYPE.

3.

Head hunters are businesses that find high end business professional for major corporations and get paid in different ways such as lump sum commission, a percentage of salary of employee found or on contract. Please develop the data model for an online system that brings head hunters and major corporations together.

11

Vous aimerez peut-être aussi