You are on page 1of 20

Tutorial 2

Two main activities:


Database design
Applications design

Focus on database design


To design the conceptual schema for a database

Applications design focuses on the programs and


interfaces that access the database
Generally considered part of software engineering

!"
Entity Relationship Model (ER Model) is a
popular high-level conceptual data model used
for the conceptual design of database
applications.
ER model has three main concepts:
Entities
Attributes
Relationships

Mini World

ER Model

Logical Level

Relational Model

DB

Physical Level

!" #
Entity

Entities are specific objects or things in the mini-world


that are represented in the database.
For example the EMPLOYEE John Smith, the Research
DEPARTMENT SEEM, the Product Xbox

Entity set: define a collection (or set) of entities that


have the same attributes.

Each entity type is described by its name and attributes.

!" # $
Attribute

Attributes are properties used to describe an entity.


For example an EMPLOYEE entity may have the
attributes Name, ID, Sex, BirthDate
A specific entity will have a value for each of its attributes.
For example a specific employee entity may have
Name='John Smith', ID='123456789', Sex='M',
BirthDate='09-JAN-55
Each attribute has a value set (or Domain or data type)
associated with it.
For example. integer, string, subrange, enumerated type,

%"

&'(

Simple versus composite


Simple (or atomic): Each entity has a single
atomic value for the attribute,
e.g. HKID or Sex.
Composite: Composition may form a hierarchy
where some components are themselves composite.
e.g. Address(StreetAddress, City, State, Zip) or
Name((FirstName, MiddleName, LastName).
Single-valued versus multivalued
Single-valued: a single value for a particular entity
e.g. Age is a single-valued attribute of person.
Multivalued: An entity may have multiple values for that attribute
e.g. a Colors attribute for a car, or a PreviousDegrees attribute
for a person.
Denoted as {Colors} or {PreviousDegrees}

%"

&)(

Stored versus derived


For example, the Age and BirthDate attributes of a person. The value of
Age can be determined from the current(todays) date and the value of
that persons BirthDate.
The Age attribute is called a derived attribute. (or be derivable from the
BirthDate attribute.)
The BirthDate attribute is called a stored attribute.

In general, composite and multi-valued attributes may be nested


arbitrarily to any number of levels, although this is rare.
For example, PreviousDegrees of a PERSON is a composite multivalued attribute denoted by {PreviousDegrees (College, Year, Degree,
Field)}
Multiple PreviousDegrees values can exist
Each has four subcomponent attributes:

College, Year, Degree, Field


8

%"

&(

Null Values: in some cases a particular entity may not have an


applicable value for an attribute.
The meaning of Null can be classified into
Not applicable
A person with no college degree would have null for College
Degree.
Unknown
Exists but is missing
If the Height attribute of a person is listed as null.
Not known
If the HomePhone attribute of a person is null.

$
Super key: any set of attributes such that the values of the
attributes (taken together) uniquely identify one entity in the
entity set
For example, HKID, SID, {NAME, SID}.
Candidate key: Minimal super key -- a super key with no
redundant attributes
For example, HKID, SID.
Primary key: A primary key is one of the candidate keys,
designated by the database designer
For example, SID.
Every primary key is also a candidate key; every candidate key
is also a super key, but not vice versa

10

!" #

+"

A relationship relates two or more distinct entities


with a specific meaning.
For example,
EMPLOYEE John Smith works on the ProductX PROJECT,
EMPLOYEE Franklin Wong manages the Research
DEPARTMENT.

The degree of a relationship set is the number of


participating entity types.
Relationship types of degree 2 are called binary
Relationship types of degree 3 are called ternary and of degree n
are called n-ary
In general, an n-ary relationship is not equivalent to n binary
relationships
11

TA
Prof.

Student
Learn

# #

&',
'(

+"

13

# #

&-,
'(

+"

14

# #

&,
-(

+"

15

+"

A relationship whose with the same participating


entity type in distinct roles.
For example, the Works-for relationship
EMPLOYEE participates twice in two distinct roles:
Manager role
Worker role
Each relationship instance relates two distinct
EMPLOYEE entities:
One employee in Manager role
One employee in Worker role
16

+"
A relationship can have attributes:
For example, HoursPerWeek of WORKS_ON
Its value for each relationship instance describes the number of
hours per week that an EMPLOYEE works on a PROJECT.
A value of HoursPerWeek depends on a particular (employee,
project) combination

For example, StartDate of MANAGES


Its value for each relationship instance describes the
date on which a manager started managing a
department

Most relationship attributes are used with M:N


relationships
In 1:N relationships, they can be transferred to the entity type on
the N-side of the relationship

17

+"
Constraints on Relationship
(Also known as ratio constraints)
Cardinality Ratio (specifies maximum participation)
One-to-one (1:1)
One-to-many (1:N) or Many-to-one (N:1)
Many-to-many (M:N)

Existence Dependency Constraint (specifies minimum


participation) (also called participation constraint)
zero (optional participation, not existence-dependent)
one or more (mandatory participation, existencedependent)

18

+"

Rectangles: entity sets


Ellipses: attributes
Diamonds: relationship sets
Double ellipses: multi-valued attributes
Dashed ellipses: derived attributes
Lines: link attributes to entity sets and entity
sets to relationship sets

. !
The bank is organized into branches. Each branch is located in a
particular city and it identified by a unique name. The bank
monitors the assets of each branch.
Bank customers are identified by their customer-id values. The
bank stores each customers name, and the street and city where
the customer lives. Customers may have accounts and can take
out loans. A customer may be associated with a particular
banker, who may act as a loan officer or personal banker for the
customer.
Bank employees are identified by their employee-id values. The
bank administration stores the name and telephone number of
each employee, the names of the employees dependents, and
the employee-id number of the employees manager. The bank
also keeps track of the employees start date and, thus, length of
employment.

You might also like