0% found this document useful (0 votes)
22 views9 pages

Lab 02

This lab manual provides instructions for creating an Entity Relationship Diagram (ERD) using Diagrams.net. It covers the objectives, steps to create entities and relationships, and includes a case study for a student course registration database. Additionally, it outlines an exercise for designing a database model for a second-hand goods enterprise and details the submission requirements for the lab report.

Uploaded by

m-ms2124181076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Lab 02

This lab manual provides instructions for creating an Entity Relationship Diagram (ERD) using Diagrams.net. It covers the objectives, steps to create entities and relationships, and includes a case study for a student course registration database. Additionally, it outlines an exercise for designing a database model for a second-hand goods enterprise and details the submission requirements for the lab report.

Uploaded by

m-ms2124181076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

School of Computer Sciences, USM, Penang

CMT221/CMM222: Database Organization and Design

Lab 02 – Creating Entity Relationship Diagram (ERD)

I. Objectives
This lab manual introduces a tool you can use to draw the Entity Relationship (ER) diagram. There are
many modeling tools that can be used to draw ER diagrams but we will learn how to draw ER diagrams
using draw.io, which can be accessed online for free. At the end of the session, you should be able to:
• Add entities and attributes
• Add key constraints (primary key and foreign key)
• Work with relationships (name describing the relationship, cardinality and connectivity)
• Create your ER diagram to fit into one page and working space

II. Introduction
In this session, you will be guided on how you can use Diagrams.net to draw ER diagrams. Before we
start, consider the following case as Example 1:

The School of Computer Sciences (CS) of ABC University needs your help to develop a new
student course registration database system. The school offers many courses for its Bachelors
of Computer Science program. Each course has a unique code and course title. Each student
enrolled in the Bachelors of Computer Science program is required to register and complete a
set of fixed core courses and non-core courses (i.e., course category). Students work on
courses and are awarded a grade in any course if they pass the course. The system needs to
record the year and semester in which the course is taken and the grade awarded to the student.
Every student has a unique ID. the system also stores the student’s name, birth date, country
of origin, email, mobile phone number and the year he/she starts the Bachelors program.

Using COURSE, STUDENT_COURSE, and STUDENT, we will create a Crow’s Foot ERD using
Diagrams.net as shown in Figure 1.

Figure 1: ER diagram in Diagrams.net

Page | 1 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
III. Getting Start
To start creating an ER diagram using Diagrams.net, kindly follow these steps:
a. Go to https://diagrams.net or https://draw.io.
b. Once the website loads, you will see the welcome screen as shown in Figure 2.
c. Click on Start. The website will then ask you where you would like to save your diagrams.
Choose “Device” to save files to your PC. This saves the “.drawio” file format that you can open
using Diagrams.net to edit.

Figure 2: Welcome Screen

d. Next, select “Create New Diagram” and choose Entity Relationship Diagram as shown in Figure
3. Then click on the blue “Create” button.

Figure 3: Choose “Entity Relationship Diagram”

e. The website will prompt you to select a location on your PC to save the XML file. Save the file
to any folder of your choice.
f. An ER diagram template will be displayed as shown in Figure 4. For this lab exercise, please
highlight and delete everything to start from scratch.

Page | 2 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
Figure 4: ERD template

IV. Creating Entity and Attribute


The main area for new shapes appears by default on the left Shapes side bar. Shapes to be added to
the diagram can be dragged and dropped from the Shapes side bar over to the canvas area (on the
right). There are many categories such as General, Misc, Advanced and Entity Relation. We will mostly
be using the shapes in the Entity Relation category.
a. To get started, close the General category and expand the Entity Relation category.
b. Drag the first “Table” icon onto the canvas area as shown in Figure 5. PK in the entity box
stands for “Primary Key”. By default, the first attribute is assigned as the primary key.

Figure 5: Create entity

Page | 3 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
c. Double click the entity name and you can change it. Name the first entity COURSE.

Figure 6: Create entity name COURSE

d. Next, double click each attribute box and enter the following attributes: “COURSE_CODE” as
the primary key, “COURSE_TITLE” and “COURSE_CATEGORY”.
e. Select the third item and press DELETE.

Figure 7: Create attributes

f. You may add a new attribute row by dragging the “Row” icon onto the table as shown in
Figure 8. Alternatively, you can also right click on a particular attribute and select “Duplicate”.

Figure 8: Add more attributes in an entity

g. Repeat steps (a) to (g) to the entity “STUDENT” with corresponding attributes as illustrated in
Figure 9.

Figure 9: Add STUDENT entity with corresponding attributes

Page | 4 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
h. Next, we will create a bridge entity called “STUDENT_COURSE” whose primary key is a
composite its foreign keys, taken from the COURSE and STUDENT entities. You may drag
the second table icon to automatically create a bridge entity with a composite key.

Figure 10: Create bridge entity

i. Fill up the corresponding attributes to obtain the three final tables as illustrated in Table 11.

Figure 11: Final COURSE, STUDENT_COURSE and STUDENT tables

j. You may edit the boxes to the left of the attribute to indicate if the attribute is a primary key
(PK) or foreign key (FK).

Figure 12: Change keys

Page | 5 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
V. Creating Relationship Type
Now you already have 3 entities defined, the next step is to add relationships between the entities.
Remember four data model basic building blocks: entities, attributes, relationships and constraints.
Diagrams.net provide multiple types of “Relationship” icons depending on the connectivity. Mouse
over the icons to see more details. Follow these steps to draw a relationship line between entities.
a. Begin by selecting the “1 Mandatory to Many Optional” icon. Drag and drop this shape onto the
canvas area as shown in Figure 13.

Figure 13: Create relationship

b. Adjust both ends by dragging one end to the COURSE entity and another end to the
STUDENT_COURSE entity. The relationship line will then connect the two entities together. You
can connect the primary key from the COURSE entity to the corresponding primary key/foreign
key in the STUDENT_COURSE entity.

Figure 14: Adjust relationship line

c. Select the relationship line. On the right side, you may change the start and end symbols if need
be.

Figure 15: Set the cardinality symbols at both ends of the relationship type

d. Add another “1 Mandatory to Many Optional” relationship between STUDENT and


STUDENT_COURSE.

Page | 6 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
VI. Setting Relationship Properties
To add text (the verb phrases), click on the relationship line between COURSE and
STUDENT_COURSE and type “is found in”. Click on the relationship line between
STUDENT_COURSE and STUDENT and type “registers” as shown in Figure 16.

Figure 16: Adding verb phrase to identify relationship

Thus, the overall ER diagram depicts the many-to-many relationship between STUDENT and
COURSES, whereby “A student can register many courses.” and “Each course can be registered by
many students.”.

VII. Saving and Exporting ER Diagrams


Finally, if you save your diagram in the “.drawio” format created by Diagrams.net, you can only open
and edit it using Diagrams.net. Diagrams.net has the ability to export the diagram in a variety of file formats.
Thus, you may also save your diagram in different formats such as JPEG and PDF so that it allows you
to share your diagram, attach it to a document or website. Select File→Export As and pick your
preferred format. If you export the diagram as any of the image formats the entire diagram will be stored
as a single image without additional whitespace.

Figure 17: Save ER diagram in different file formats

You are done! You can use Diagrams.net to draw ER diagrams for your group project. Hand-drawn
ERDs are not accepted.

Page | 7 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS
VIII. Exercise

Building Your Data Model

SecondStreet is an enterprise selling second-hand imported goods to consumers. Due to an increase


in demand from customers, the management team at SecondStreet has decided to open a new chain
store to expand their enterprise. Thus, the management needs a new database system to improve the
existing record-keeping system.

As SecondStreet’s systems analyst, you are hired to create a database design that will improve the
record-keeping of SecondStreet’s business data specific to their new chain store. You decide to build
a logical database model using an ERD from the following business rules and data that you have
collected from interviews. Your plan is to use your ERD as a communication tool to show the
SecondStreet management team the data you plan to include in their new database.

Business Rules

1. An employee can be assigned only one position. A position can be assigned to many
employees.
2. A customer can be serviced by one employee. An employee can service zero or many
customers.
3. An employee can process many orders. An order can be processed by one employee.
4. A customer can place many orders. An order is can be placed by only one customer.
5. An order can list many products. A product can be listed in an order only once.
6. A product can be on many orders.
7. A product can be supplied by many vendors. A vendor can supply many products.

Data

Employee: employee ID, name, IC number, address, mobile phone number, basic salary, hire date

EmployeePosition: employee position ID, position short name, position description

Customer: customer ID, name, address, mobile phone number, membership date, status

Order: order ID, order date, payment type, order total amount (sum of all the total product amounts
for a given order), order status

OrderProduct: order ID, line number, product ID, quantity, product unit price, total product amount
(quantity multiplied by unit price), back order status

Product: product ID, product name, product type, quantity on hand, product unit cost, product unit
price, inventory value (quantity on hand multiplied by product unit cost)

Vendor: vendor ID, vendor name, address, phone

VendorProduct: vendor product id, vendor ID, product ID, quantity supplied

Instructions
Create your ERD Data Model in Crow’s Foot Notation using Diagrams.net. Include also the
cardinalities (e.g., (1,1), (1,M) or (0,M)) beside the entities in the diagram. You will need to
figure out how to add cardinalities to your ERD in Diagrams.net.
Page | 8 CMT221/CMM222: Database Organization and Design (LAB 02)
LSY, TJS
Note: To map one-to-many (1:M) relationships, the primary key on the “one side” of the
relationship is added to the “many side” as a foreign key.

IX. Lab Report Submission


Besides student’s name and matrix number, the lab report must contain the following:
• Complete ERD for Example 1 using Diagrams.net.
• Solution for Exercise 1 using Diagrams.net.

Save all your ER diagrams in PDF format and submit in the Lab 02 assignment dropbox on
elearn@USM at the end of your lab session. Lab report submission will count towards your coursework
grade.

~~END OF LAB 02~~

Page | 9 CMT221/CMM222: Database Organization and Design (LAB 02)


LSY, TJS

You might also like