Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

COMM 335 - Information Systems

Technology and Development

Winter 2019 – Term 1

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 1


Database Design

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 2


Learning Objectives

1. Design a relational database using Entity


Relationship Diagram (ERD)

2. Discuss the problems or anomalies caused by


unnormalized databases and the need for Data
Normalization

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 3


Learning Objective 1

Design a relational database using Entity


Relationship Diagram (ERD)

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 4


Database Modeling

 Also called data modeling, is a technique


used to develop an anomaly-free database
with database integrity.
 A model is a representation of real objects,
events, or systems.
 Most models are built using specific symbols.
 Models are used for understanding, analyzing,
and documenting real systems.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 5


Database Modeling (cont’d)

 When designing a database, you can think of it as


three different realms (domain):
 Database designer
 Database builder
 Database user

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 6


Database Modeling Notation

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 7


What is Entity Relationship
Diagram (ERD)?

 Entity Relationship Diagram (ERD) depicts the


relationship among entities in the database.
 The ERD shows:
 Entities: Customer, Sales Order, Item
 Relationship between Entities: customer places an
order
 Relationship Cardinality: one-to-one (1:1), one-to-
many (1:M), or many-to-many (M:N).

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 8


Entity Relationship Diagram
(ERD)

An order is
placed by only
one customer.

A customer may
place zero or
more orders.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 9


Database Entities
 Entity: A person, object, event, or concept in
the user environment about which the
organization wishes to maintain data, e.g.
 Person : STUDENT, CUSTOMER
 Object : PRODUCT, BUILDING
 Event : SALE, REGISTRATION
 Concept : ACCOUNT, COURSE

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 10


Attributes
 Attribute: A property or characteristic of an
entity, e.g.
 CUSTOMER : CustomerNo, Name, Address, Phone
 EMPLOYEE: EmployeeID, Name, HireDate

 Originally shown in data models as ellipses.


 Data modeling products today commonly show
attributes in rectangular form.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 11


Attributes in Ellipses

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 12


Attributes in Entity Rectangle

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 13


Entity Identifiers

 An attribute (or a combination of attributes) that


uniquely identifies an entity occurrence, e.g.
 CustomerNo of CUSTOMER entity.
 Identifiers in data models become candidate
keys in database design
 Entities have identifiers.
 Tables (or relations) have keys.
 The candidate key selected for identifying the
entity occurrence is the Primary key.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 14


Entity Relationships

 An Entity Relationship Diagram (ERD) shows


the relationships among entities.
 Three different types of relationships among
entities are:
 One-to-one relationships (1:1)
 One-to-many relationships (1:M)
 Many-to-many relationships (M:N)

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 15


Entity Relationships (cont’d)

 For a single occurrence of one entity (one


customer), cardinality defines the maximum
and minimum number of occurrences that
might relate to the other entity (sales orders).
 The name given to the relationship (one-to-
one, one-to-many, and many-to-many) refers to
the maximum cardinalities.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 16


Entity Relationship Diagram (ERD)
with Crow’s Feet Symbols

Step 1: What is the maximum number Step 3: What is the maximum number of
of orders a customer can place? customers who can place a specific
Many order? One

Step 4: What is the minimum number of


Step 2 What is the minimum number customers who can place a specific order?
of orders a customer can place? Zero One

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 17


How To Build an ERD

 Step 1: Determine the relevant business transactions


that the organization must support.
 Step 2: Determine the business rules for a specific
business transaction.
 Step 3: Determine business entities and the
relationship among them.
 Step 4: Determine the entity identifier(s) for each
entity.
 Step 5: Draw entity relationship diagram.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 18


How To Build an ERD (cont’d)

 Step 6: Optimize the entity relationship diagram by


removing many-to-many relationships.

 Step 7: Add business-related attributes to the entity


relationship diagram.

 Step 8: Implement relationships.

 Step 9: Develop relational database tables.

 Step 10: Build relational database tables.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 19


ERD Relationship
Cardinality Symbols

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 20


One-to-Many Relationship
Possibilities

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 21


Use Intersection Table to Remove
Many-to-Many Relationships

Intersection
Table

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 22


EspressoCoffee Sales Transaction
ERD with Foreign Keys

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 23


Conceptual Database Tables

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 24


In-Class Exercise One
 Draw an ER diagram to represent the following description:
 A professor may teach a minimum of zero and a maximum of
three classes.
 The minimum number of professors required to teach a class is
one, as is the maximum number of professors.
 A class may contain no students at all or that up to thirty
students may be enrolled.
 A student must take at least one class but no more than five
classes

 You should specify all the elements including entities,


attributes, relationships, and cardinality.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 25


From the ER Diagram to the
Relational Database

ER Diagram Database
Entities Tables
Attributes Columns/Fields
One-to-many Primary key to foreign key of the
child table
Many-to-many 3 tables: 2 parent tables and an
intersection table

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 26


In-Class Exercise Two

 Translate the ER diagram in the previous


exercise to the relational database design.

 You should include all columns and specify


the primary and foreign keys.

Solutions will be discussed in class.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 27


Learning Objective 2

Discuss the problems or anomalies caused


by unnormalized databases and the need
for Data Normalization

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 28


Database Integrity

 Database Integrity refers to the database


containing accurate, valid and complete data.

 Rule 1. Entity Integrity. Each record in the database


must have a unique identifier (i.e. a unique primary
key). No two records in the database table can have
the same primary key value.

 Rule 2. Primary Key Integrity. The primary key value


cannot be null (empty). Each record must have a value
for the primary key field.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 29


Database Integrity (cont’d)

 Rule 3. Domain Integrity. The field values must be


from a predefined domain.
o For example, the Date field must have a date and not any
other values.

 Rule 4. Referential Integrity. Data referenced and


stored in related tables must be consistent across the
database.
o For example, a customer address should be the same in
any table in which it is referenced. Referential integrity is
improved when the customer address is stored in one
location only.
Details to be covered
in the Tutorials.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 30


Database Anomalies
 Database anomalies are three types of problems in
database tables:
1. Deletion Problem. Deleting one record (customer) causes
deletion of other records.
2. Update Problem. Updating one field (address) requires updating
multiple fields.
3. Insertion Problem. Inserting a new field (customer) is problematic
because the primary key is null.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 31


Deletion Anomalies

 Deletion problem. Deleting Vincent as a customer will


cause the deletion of four records. These four records
hold vital information about four orders and four items.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 32


Update Anomalies

 Update problem. To update Vincent’s customer


address, four records would need to be updated.
What happens if one of these four
records is not updated?

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 33


Insertion Anomalies

 Insertion problem. To identify a unique record, we have to


use the customer number, order number, and item number.
That means these three fields together form the primary key.
If we want to insert a new customer who hasn’t placed an order
yet, then the order number and item number fields would be
empty.
This violates database integrity Rule No 2:
The Primary Key Value Cannot Be Null.)

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 34


Anomaly-Free Databases

 A well-designed
database is free of
Deletion, Update,
and Insertion
(DUI) anomalies.
 Database
anomalies are
removed through
a process called
Normalization
and/or database
design modeling.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 35


Accountants and Data
Normalization
 Update anomalies can generate conflicting and
obsolete database values.
 Insertion anomalies can result in unrecorded
transactions and incomplete audit trails.
 Deletion anomalies can cause the loss of
accounting records and the destruction of audit
trails.

Accountants should understand data normalization and


be able to determine whether a database is properly
normalized.

© 2019 – Y.M. Cheung COMM 335 - Winter 2019 Term 1 36

You might also like