14
Designing an ERD based on scenarios Lesson 3 (cont’d)

Lecture 3b (1).ppt

Embed Size (px)

Citation preview

Page 1: Lecture 3b (1).ppt

Designing an ERD based on scenarios

Lesson 3 (cont’d)

Page 2: Lecture 3b (1).ppt

2

Lesson Outcomes

At the completion of this lesson, students should be able to:

(1) extract ERD components from a given database scenario

(2) draw an ERD based on a given database scenario

(2) suggest the appropriate data/information that a company could store in its database

Page 3: Lecture 3b (1).ppt

3

Steps in drawing ERD

From the given scenario:

(1) identify the main entities – draw rectangle

(2) identify the relationships among the entities – draw diamond

(3) identify the attributes of each entity – underline the primary key if any – draw oval

(4) revisit the ERD

NOTE: All entities should be involved in at least 1 relationship

Page 4: Lecture 3b (1).ppt

4

Identify the main entities

• Look for items/nouns which can be described in more detail.

Example a car is an entity since it can be described in terms of color, manufacturer, engine capacity, etc. Similarly, manufacturer is also an entity if it can be described in terms of address, no of employees, etc.

Another example, a registration form is also an entity since it has many information such as student id, date, classes registered etc.

Page 5: Lecture 3b (1).ppt

5

Identify the relationshipsOne technique to identify relationship is:• Draw table with all entity names as column & row headers

• Fill in cell with verb if the row and column entities have relationship with each other

Entity1 Entity2 Entity3 Entity4

Entity1

Entity2

Entity3

Entity4

Entity1 Entity2 Entity3 Entity4

Entity1 owns

Entity2 has

Entity3 produces

Entity4 takes gives

Page 6: Lecture 3b (1).ppt

6

Identify the relationships – cont’d

• Map the relationships to the ER diagram• Proceed with the constraints:

– How many entities involved (degree) ?– What is the connectivity of the relationship (1:1, 1:M, M:N) ?– What is the cardinality of the relationship (min-max # of instances) ?

OPTIONAL

Page 7: Lecture 3b (1).ppt

7

Identify the attributes

• Attributes are characteristics of an entity. It should contain information which cannot be further broken.

Example, student is an attribute if you just want to keep the name of the student in the database.

• Primary key is an attribute which is unique for each instance of the entity. Example, an entity car has engine capacity as one of its attributes. If you have 100 cars, will each car has different engine capacity, if yes, then it is a primary key, otherwise, it’s not

Page 8: Lecture 3b (1).ppt

8

Revisit the ERD

• Look for M:N relationships – change the diamond into rectangle symbol. Create a new relationship from entity1 to the newly created entity with 1:M connectivity & from the newly created entity to entity2 with M:1 connectivity.

• Look for multivalued attributes – create a new entity for the attribute. Create a key attribute for the new entity. Link the original entity with the newly created entity with 1:M connectivity if each value is unique to an instance, otherwise M:N

• Look for composite attributes – if each sub-attribute’s value is unique for each instance, then include each sub-attribute in the entity. Otherwise, create a new entity, and link the new entity to the original with connectivity M:1.

Page 9: Lecture 3b (1).ppt

9

Sample Exercise 1

• Draw an ERD to represent the database for the following MAIL_ORDER database in which employees take orders for parts from customers. The data requirements are summarized as follows:– The mail order company has employees, each identified by a unique

employee number, first and last name, and ZIP code.

– Each customer of the company is identified by a unique customer number, first and last name, and ZIP code.

– Each part sold by the company is identified by a unique part number, a part name, price, and quantity in stock.

– Each order placed by a customer is taken by an employee and is given a unique order number. Each order contains specified quantities of one or more parts. Each order has a date of receipt as well as an expected ship date. The actual ship date is also recorded.

Page 10: Lecture 3b (1).ppt

10

Sample Exercise 2

• Draw an ERD to represent the database for the following scenario:

A company has several departments. Each department has a supervisor and at least one employee. Employees must be assigned to at least one, but possibly more departments. At least one employee is assigned to a project, but an employee may be on vacation and not assigned to any projects. The important data fields are the names of the departments, projects, supervisors and employees, as well as the supervisor and employee number and a unique project number.

Page 11: Lecture 3b (1).ppt

11

Sample Exercise 3

• Suggest the entities, attributes and relationships which might be applicable for a bus company database.

• Draw the ERD to represent your suggestion.

Page 12: Lecture 3b (1).ppt

12

Sample Exercise 4

• Draw an ERD to represent a database which can be used to store information on the coming world cup soccer championship.

Page 13: Lecture 3b (1).ppt

13

Sample Exercise 5

• Suggest the entities, attributes and relationships which exist in the form below & draw an ERD for them.

Page 14: Lecture 3b (1).ppt

14

Constructing ERD for relational database model

• ERD can represent conceptual model – general for all databases.

• ERD can also be refined to represent logical model – specific to chosen database model, e.g. relational model

• If that’s the case, then the model needs to be further refined according to the chosen model’s requirements:– No M:N relationship should exist– No composite and multivalued attributes should exist– Primary and foreign key must be specified– Etc.