0% found this document useful (0 votes)
44 views78 pages

Database Modeling 2

The document discusses database modeling and conceptual schema design. It introduces key concepts such as entity sets, relationships, and attributes that make up an entity-relationship (ER) diagram. An example ER diagram is shown for a university database with entity sets for students, courses, and an enrollment relationship. The document also covers modeling choices like whether an attribute is part of an entity or relationship, and existence relationships where one entity set can only exist through its relationship to another entity set.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views78 pages

Database Modeling 2

The document discusses database modeling and conceptual schema design. It introduces key concepts such as entity sets, relationships, and attributes that make up an entity-relationship (ER) diagram. An example ER diagram is shown for a university database with entity sets for students, courses, and an enrollment relationship. The document also covers modeling choices like whether an attribute is part of an entity or relationship, and existence relationships where one entity set can only exist through its relationship to another entity set.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 78

CS480: Database Systems

Database Modeling

Databases

Modeling
or
Data
representation
(of an enterprise)

Management of
the data

Management is added value of DBMS over File Representation


DDL & DML

Levels of Abstraction in a
DBMS
End-user

Program
A

Program
B
Program
C
Use DML

Levels of Abstraction in a
DBMS
External Schema

End-user

View 1
Program
A

Program
B
Program
C
Use DML

View 1

Levels of Abstraction in a
DBMS
C
External Schema

End-user

View 1
Program
A

Program
B
Program
C
Use DML

View 1

O
N
C
E
P
T
U
A
L

S
C
H
E
M
A

Levels of Abstraction in a
DBMS
C
External Schema

End-user

View 1
Program
A

Program
B
Program
C
Use DML

View 1

O
N
C
E
P
T
U
A
L

S
C
H
E
M
A

External, Conceptual and Physical Schemas


Defined by DDL

Database:
Organized
according
to physical
schema.

Levels of Abstraction in a
DBMS
C
External Schema

End-user

View 1
Program
A

Program
B
Program
C
Use DML

View 1

O
N
C
E
P
T
U
A
L

Database:
Organized
according
to physical
schema.

S
C
H
E
M
A

External, Conceptual and Physical Schemas


Defined by DDL
DDL+DML = Data Model

Instances and Schemas


Similar to types and variables in
programming languages.
Conceptual Schema - the logical
structure and design of the database
Relatively Fixed
Analogous to type information in a program

Database Instance - the actual content


of the database at a particular point in
time
Analogous to the value of variable

Instances and Schemas


Schema for STUDENT:
SS#

Name

Address

Major

Instance for STUDENT:


SS#

Name

Address

Major

12345

Alice

Chicago

CS

23456

Bob

Joliet

ECE

34567

Charles

Gary

CME

45678

Dan

Chicago

CS

Design of the Conceptual Schema


(Data Modeling)
Building Blocks of Data Modeling
Entity Sets: Set of abstract (course) or
concrete (student) objects that are
distinguishable.
Are there objects that are not
distinguishable?

Relationships: Association of several


entity sets

University System Example


Entity Sets
STUDENT, COURSE

Relationship
ENROLLMENT
STUDENT is enrolled in a COURSE

University System Example


Relationships could include several entity
sets
Following example is a ternary
relationship
Entity Sets:
STUDENT, COURSE, SEMESTER (abstract?)

Relationship:
ENROLLMENT
STUDENT is enrolled in a COURSE during a
SEMESTER

Entity Sets and


Relationships
Each entity set and relationship has:
Name
Attributes

An attribute is a property of an entity


or a relationship
Ex. Attributes of a STUDENT entity set
Student-id, name, address, major, etc.

Ex. Attributes of ENROLLMENT relationship


Grade

Entity Sets and


Relationships
Entity Sets and Relationships are
represented in the computer as a set
records.
STUDENT:

ENROLLMENT:

Studentid

Name

Address

Major

12345

Alice

Chicago

CS

23456

Bob

Joliet

ECE

34567

Charles

Gary

CME

45678

Dan

Chicago

CS

Student-id

Course Name

Grade

12345

CS 480

12345

CS 401

34567

CME 508

Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM

Is the attribute PRICE a property of the ITEM or


of SUPPLIES?
Could be modeled either way
The choice will affect how the database will be used.

Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM

Is the attribute PRICE a property of the ITEM or


of SUPPLIES?
Could be modeled either way
The choice will affect how the database will be used.

Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM

Is the attribute PRICE a property of the ITEM or


of SUPPLIES?
Could be modeled either way
The choice will affect how the database will be used.

Entity-Relationship (ER) Diagram


Visual tool for designing the
conceptual schema
Proposed by Peter Chen in 1976
Entity
Set
Relationship
Set
Attribut
e

ER Diagram
Example:

SUPPLIER

ITEM

ER Diagram
Example:

SUPPLIER

SUPPLIES

ITEM

ER Diagram
Example:

Weigh
t
Price

SUPPLIER

Supp.
Name

SUPPLIES

Supp.
Address

Color

ITEM

Item
Name

Representation of Ternary
Relationships

Course

Enrollmen
t

Semester

Student

Whats Next?
Observations about relationships
Functionality of Relationships
Special Types of Relationships
Existence
Is-a

Keys
Comprehensive Data Modeling
Example

Observations about Relationships


There can exist a relationship set
between the same entity set:

Observations about Relationships


There can exist a relationship set
between the same entity set:
University
Database

Course

PreReq

Observations about Relationships


There can exist a relationship set
between the same entity set.
Different roles for the entity set.
University
Database

Company
Database

Course

Employee

PreReq

Manages

Observations about Relationships


There can be more than one
relationship set between a pair of
entity sets:
Company Database:

Manages

Employee

Project

Work-on

Observations about Relationships


There can be more than one
relationship set between a pair of
entity sets:
University Database:

Takes

Student

Course

TAs

Functionality of
Relationships
Mapping Cardinality Constraints
Express the number of entities to which
another entity can be associated via a
relationship set
Most useful in describing binary
relationship sets.

One to One
For each member of entity set A
there is at most one related member
of B.
Ex:

Men

Marriag
e

Arrow points toward the singular entities

Women

One to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of B, there is at
most one member of A.

One to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of B, there is at
most one member of A.
Men

Fathers

Children

Arrow points toward the singular entities

Many to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of entity set B,
there are zero or more related
member of A.
SUPPLIER

SUPPLIES

ITEM

Many to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of entity set B,
there are zero or more related
member of A.
SUPPLIER

SUPPLIES

ITEM

Course

Enrollmen
t

Student

Mapping Cardinality
Constraints

One to
one

One to many

Note: Some elements in A and B may not be mapped to any


elements in the other set

Mapping Cardinality
Constraints

Many to
one

Many to many

Note: Some elements in A and B may not be mapped to any


elements in the other set

Relationship Instance
A

Relationship Instance
A

Database Instance of R

Relationship Instance
A

Database Instance of R
Is it a possible instance of R?

Relationship Instance
A

Database Instance of R
Is it a possible instance of R?
Is R then One to One?

Relationship Instance
A

Database Instance of R
Is it a possible instance of R?
Is R then One to One?
Separation of Database Schema
and Database Instance

Existence Relationships
A one to many relationship set R,
between entity sets A and B
indicates existence-dependence
if an entity set of type B can exist in
the database only if it is related to an
entity of type A.
B is called a dominated entity set.
R is represented by:

B represented by:

Existence Relationships
A company wants to store information about the
children of employees.

Existence Relationships
A company wants to store information about the
children of employees.
SS#

Salary

Employee

Last
Name

Father
s

First
Name

Child

name

Birt
h
Date

Existence Relationships
In a university system: modeling courses and
their possible sections.
Semeste
r

Credit
s

Course

Cours
e
id

Course
-sec

Section

Year
Title

Section
id

Existence Relationships
Should Works-on be an existence relationship?

Employee

Works
on

Project

Existence Relationships
Should Works-on be an existence relationship?

Employee

Works
on

Project

Will depend on company policy.


If project can be worked on by at most one employee
AND every project must have at least one employee working

Existence Relationships
A company wants to store information about the
children of employees.
SS#

Salary

Employee

Last
Name

IMPLICATIONS?

Father
s

First
Name

Child

name

Birt
h
Date

Existence Relationship
SS#

First
Name

Last
Name

Salary

12345

Alice

Allen

100K

23456

Bob

Barry

50K

34567

Charles

Cole

20K

45678

Dan

Dole

200K

Dads SS#

Child Name

Birthdate

12345

Amy

1/1/10

23456

Bill

2/2/09

12345

Andy

3/3/11

45678

Dave

4/4/07

45678

Dylan

5/5/05

Existence Relationship
SS#

First
Name

Last
Name

Salary

12345

Alice

Allen

100K

23456

Bob

Barry

50K

34567

Charles

Cole

20K

45678

Dan

Dole

200K

Dads SS#

Child Name

Birthdate

12345

Amy

1/1/10

23456

Bill

2/2/09

12345

Andy

3/3/11

45678

Dave

4/4/07

45678

Dylan

5/5/05

Existence Relationship
SS#

First
Name

Last
Name

Salary

23456

Bob

Barry

50K

34567

Charles

Cole

20K

45678

Dan

Dole

200K

Dads SS#

Child Name

Birthdate

12345

Amy

1/1/10

23456

Bill

2/2/09

12345

Andy

3/3/11

45678

Dave

4/4/07

45678

Dylan

5/5/05

Existence Relationship
SS#

First
Name

Last
Name

Salary

23456

Bob

Barry

50K

34567

Charles

Cole

20K

45678

Dan

Dole

200K

Dads SS#

Child Name

Birthdate

12345

Amy

1/1/10

23456

Bill

2/2/09

12345

Andy

3/3/11

45678

Dave

4/4/07

45678

Dylan

5/5/05

Existence Relationship
SS#

First
Name

Last
Name

Salary

23456

Bob

Barry

50K

34567

Charles

Cole

20K

45678

Dan

Dole

200K

Dads SS#

Child Name

Birthdate

23456

Bill

2/2/09

45678

Dave

4/4/07

45678

Dylan

5/5/05

If an element of the dominating set is deleted, then its


related elements in the weak set should also be deleted.

ISA Relationship
If each entity in the entity set B is a
particular type of entity in entity set
A then we say that B isa A.
Namely, there is an ISA relationship
between A and B.
Specialization

ISA Relationship Example


SS#

Salary

Name

Address

Hospital
Employee

ISA

Physician

ISA

Specializatio
n

Work
Hours

Lab
Technician

Observations about ISA


relationships
Is always One to One
Induces a specialization hierarchy in the ERdiagram
Eg. A ISA B ISA C

If A ISA B then all the attributes of A are


inherited by B.
The Lab Technician has a salary and ss#, etc.

Lower level classes dont share attributes


A physician doesnt have work hours and a lab
technician doesnt have a specialization.

Keys
Def: The key of an entity set E is a
minimal subset of the attributes of E
that uniquely indentifies an entity in
the set.
This subset of attributes adequately
distinguishes between elements of
the entity set.

Keys
name
address

Student

Studentid

Keys
Is {name}
a key?

name
address

Student

Studentid

Keys
Is {name}
a key?

name
address

Is {address}
a key?

Student

Studentid

Keys
Is {name}
a key?

name
address

Is {address}
a key?

s {student-id, address}
a key?

Student

Studentid

Keys
name
address

{student-id}

Minimal
Uniquely identifies
a student

Student

Studentid

Keys
name
address

{student-id}

Minimal
Uniquely identifies
a student

Student

Keys in the
ER-diagram are
underlined.
Studentid

What is key for actors?


Age

Year
Salar
y

Middle
Initial

Actors

First
Name

Title

Movies

Starred-in

Last
Name

Lengt
h
Film Type

What is key for Movies?


Age

Year
Salar
y

Middle
Initial

Actors

First
Name

Title

Movies

Starred-in

Last
Name

Lengt
h
Film Type

Keys
Age

Year
Salar
y

Middle
Initial

Actors

First
Name

Title

Movies

Starred-in

Last
Name

Lengt
h
Film Type

Keys for ISA Relationships


SS#

Salary

What is the key


for Physician and
Lab Technician?

Name

Hospital
Employee

ISA

Physician

Address

ISA

Specializatio
n

Work
Hours

Lab
Technician

Keys for ISA Relationships


If A is a B then the key of B are
attributes inherited from A.
Key for a Physician or for a Lab
Technician is inherited from Hospital
Employee entity set. Their keys are
the SS#.

Keys for Dominated Entity


Sets
SS#

Salary

Employee

Last
Name

Child

Father
s

First
Name

name

Birt
h
Date

What is the key for Child?

any of these keys: {name}, {Birth Date}, {name,BirthDate}

Keys for Dominated Entity


Sets
SS#

Salary

Employee

Last
Name

Father
s

First
Name

Child

name

Birt
h
Date

Key for Child will include key attributes for Employee.


{SS#, name}

Keys for Dominated Entity


Sets
SS#

Salary

Employee

Last
Name

Father
s

First
Name

Child

name

Birt
h
Date

In general, a dominated entity sets key may include


attributes in the dominating set.

Keys of a Relationship Set


The key of a relationship set R is a
minimal set of attributes (not
necessarily of R) that uniquely
identifies a relationship in the set.

Keys of a Relationship Set


Weigh
t

Supplie
r
Id

Price

SUPPLIER

SUPPLIES

Color

PART

Part Id
Supp.
Name

Supp.
Address

Item
Name

What is key for SUPPLIES?

Keys of a Relationship Set


Weigh
t

Supplie
r
Id

Price

SUPPLIER

SUPPLIES

Color

PART

Part Id
Supp.
Name

Supp.
Address

Item
Name

Usually we take keys of participating entities: {SuppId, Part

Keys of a Relationship Set


Supplie
r
Id

Weigh
t
Price
Date

SUPPLIER

Color

PART

SHIPMEN
T

Part Id
Supp.
Name

Supp.
Address

What is key for SHIPMENT?

Item
Name

Keys of a Relationship Set


Supplie
r
Id

Weigh
t
Price
Date

SUPPLIER

Color

PART

SUPPLIES

Part Id
Supp.
Name

Supp.
Address

Item
Name

The key may also involve a relationship attribute.

Exercise ER-Diagram
Database System for an Airline to be
used for:
Booking Flights
Managing Flights, Crew Members, and
their Planes

Construct an ER-diagram for this


Airline Enterprise.

You might also like