0% found this document useful (0 votes)
316 views

DBMS Session 3 Notes

The superkey for the Book entity set would be the combination of attributes {title, author}. This combination uniquely identifies each book in the collector's collection.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views

DBMS Session 3 Notes

The superkey for the Book entity set would be the combination of attributes {title, author}. This combination uniquely identifies each book in the collector's collection.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 41

CS 623 – Database Management Systems

Session 3 Agenda

 Chapter 2 Team Assignments Questions


 Oracle Installation Questions (begin using Oracle in Week 4)
 Chapter 3: Entity Relationship Model
 Chapter 3 Team Assignment Review
 Chapter 3 Individual Assignment Review
 Team time
Chapter 3: The Entity Relationship Model

Purpose of E-R Model

 E-R Model – (Entity Relationship Diagram, ERD, ER Diagram)


 Describes the major entities and their inter-relationships
 Expresses the conceptual properties of the database.
 Conceptual model which is independent of any DBMS.
Chapter 3: The Entity Relationship Model

Basic Symbols for E-R Diagram


Chapter 3: The Entity Relationship Model

Basic Symbols for E-R Diagram (Con’t)


Chapter 3: The Entity Relationship Model

Entity

 Represented by an Rectangle on an E-R Diagram


 Entity is any object that exists and can be distinguished from other
objects
 Can be a person, place, event, object, concept in real world
 Can be physical object or an abstraction
 Entity instance is a particular person, place, etc.
 Entity type is a category of entities
 Entity set is a collection of entities of the same type
 Intension of entity – permanent part of the relation.
 Extension of entity –  values that populate these data structures.
Chapter 3: The Entity Relationship Model

Attribute

 Represented by an Oval on an E-R Diagram. A line connects the attribute oval to


the entity rectangle that it describes.
 The attributes of an entity are the defining properties or qualities of the entity
type.
Ex: the defining properties of student entity are: stuID, lastname, firstname, major,
credits.
 Domain of the attribute– set of allowable values for attribute. Ex: credit would
be between 0 – 150.
 Attribute may have null values.
 Composite attribute – some attributes can be decomposed into smaller
elements. Ex: Address can be broken down into street, city, state, zip, country.
 Derived attribute – value that can be calculated from other sources. Ex, age can
be calculated from date_of_birth
Chapter 3: The Entity Relationship Model

Keys

 Superkey is an attribute or set of attributes that uniquely identifies a


row in a table.
Ex an attribute stuid of student table because it can uniquely identify
each student.
Ex a set/combination of attributes could be {stuid, credits}

 Candidate key is a superkey with no redundant data.


Ex: studid or social security number is but credits is not.

 Composite key is a key of two or more attributes that uniquely


identifies the row. Ex: {lastname, firstname, address}

 Primary key is the candidate key chosen identifying entities and


accessing records. Ex: stuid
Chapter 3: The Entity Relationship Model

Keys (Con’t)

 Alternate key is the candidate key which are not selected as the
primary key. Ex: if social security number is stored on table.

 Secondary key: attribute or set of attributes used for accessing


records, but not necessarily unique. Ex: LastName

 Foreign key is a key that references the primary key of another


table – used to establish the parent/child relationship.
Chapter 3: The Entity Relationship Model

Relationships

 Represented by diamond on E-R diagram


 Relationships are the connections or interactions between entity
sets. Ex: a student may be related to a class by being enrolled in that
class.
 Relationship type represents the association between entity types. 
Ex: Enroll is a relationship type that exists between entity type
Student and Class.
 Relationship set is collection of relationships of same type.
Chapter 3: The Entity Relationship Model

Degree of the Relationship

Degree of the relationship is the number of different entity


sets participating in a relationship.
 Unary(recursive) – when both participants in the relationship are
the same entity. An entity has a relationship with itself.
Ex: person is married to only one person. Degree = 1
Ex: a person has only one passport and only one passport is given to
only one person
 Binary - two entities are involved in the relationship. Example
student is enrolled in Class. Degree = 2
 Ternary - three entities are involved in the relationship. Example
students, classes, faculty. Degree = 3
 N-ary - n entities involved in the relationship
Chapter 3: The Entity Relationship Model

Cardinality of the Relationships

Number of entity instances to which another entity instance can map under the
relationship
One-to-one: X:Y is 1:1 is each entity in X is associated with at most one entity
in Y and each entity in Y with at most one entity in X. Example: Each student
has only one student ID, and each student ID is assigned to only one person.

One-to-many: X:Y is 1:M is each entity in X can be associated with many


entities in Y, but each entity in Y with at most one entity in X. (many=more
than one). Example: University (primary table) can have many students
(dependent table). A student cannot study in multiple universities at the same
time.

Many-to-many: X:Y is M:M if each entity in X can be associated with many


entities in Y, and each entity in Y with many entities in X. Example: A student
can register for many classes, and a class can include many students.
Chapter 3: The Entity Relationship Model

Examples of Cardinality on an E-R Diagram


Chapter 3: The Entity Relationship Model

Relationship Participation Constraints

 Partial Participation
 Represented by single line from entity rectangle to relationship diamond
 Not every entity instance must participate
Using University example:
 Some students may not be enrolled in any class
 Some classes may have no students enrolled
 Some faculty may not be teaching any class
 Total Participation
 Represented by double line from entity rectangle to relationship diamond
 Every member of entity set must participate in the relationship
Using University example:
 Every class must have a faculty teaching it
Chapter 3: The Entity Relationship Model

Examples of Total vs. Partial Participation in a Relationship


Chapter 3: The Entity Relationship Model

(min, max) Notation to Cardinality

An alternate representation that shows both participation and cardinality


constraints is (min,max) notation:
 Min specifies the least number of relationship instances an entity
instance must participate in
 can be 0 (partial participation)
 or 1 or more (total participation)
 Max is the greatest number of relationship instances the entity can
participate in
 can be 1
 or many ( written M,N, or *)
 or some constant integer
Written on line connecting entity rectangle to relationship diamond
Chapter 3: The Entity Relationship Model

Example of (min, max) notation for University E-R Diagram


Chapter 3: The Entity Relationship Model

Explanation of (min,max) notation for University E-R Diagram

 The line from Student to the HasMajor relationship diamond has


(0,1), which means a student does not have to have any major, and
has at most one major.
 The line connecting Department to the HasMajor relationship
diamond has a min of 0, indicating that a department does not need
to have a student majoring in it, and a max of M, indicating that a
department can have many student majors.
 The (1,M) on the line connecting Department to the Employs
relationship has a min of 1, meaning a department must have at
least one faculty member, and a max of M, since a department can
have many faculty.
 The line from Faculty to the Employs relationship has (1,1),
indicating that a faculty member belongs to exactly one department.
Chapter 3 Questions?
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Question

A private book collector is designing a database to keep track of her


purchases and book holdings.
Consider the entity set Book with attributes title, author, publisher,
pubDate, numberPages, condition, cost, and datePurchased.

a. Show how the entity set and its attributes would be represented on
an E-R diagram.
b. Identify a superkey for the Book entity set.
c. Identify all candidate keys for the entity set.
d. Identify a primary key for the entity set and underline it on the E-R
diagram.
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer

a. Show how the entity set and its attributes would be represented
on an E-R diagram.

Entity set Book with attributes: title, author, publisher, pubDate,


numberPages, condition, cost, datePurchased
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

a. Show how the entity set and its attributes would be represented
on an E-R diagram.
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

b. Identify a superkey for the Book entity set.

Recap: Superkey is an attribute or set of attributes that uniquely


identifies a row in a table.
Ex an attribute stuid of student table because it can uniquely identify
each student.
Ex a set/combination of attributes could be {stuid, credits}
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

b. Identify a superkey for the Book entity set.

If we assume the book collector:


 never has two copies of the same book
 never has two books with the same title
 stores only the first author’s name if the book has multiple authors
then title is a superkey, and so is {title, author}.

If the assumptions about title are not valid, some combination such as
{title, author}, or {title, author, datePurchased} may be needed as a
superkey.
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

c. Identify all candidate keys for the entity set.

Recap: Candidate key is a superkey with no redundant data.


Ex: studid or social security number is but credits is not.
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

c. Identify all candidate keys for the entity set.

Under our initial assumptions in part (b), the candidate key is: title
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

d. Identify a primary key for the entity set and underline it on the
E-R diagram.

Recap: Primary key is the candidate key chosen identifying entities


and accessing records. Ex: stuid
Chapter 3: The Entity Relationship Model

Exercise 3.2 – Book Answer (Con’t)

d. Identify a primary key for the entity set and underline it on the
E-R diagram.

The primary key is title, if that is the only candidate key.


Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Question (Con’t)

Assume that in the same scenario as in Exercise 3.2, there is an


additional entity set called Purchase with attributes orderNumber,
purchaseDate, totalAmount. A purchase may include several
books.

a. Show how this entity set Purchase and its relationship to Book
would be represented on the E-R diagram.

b. Stating any necessary assumptions, make a decision about the


cardinality and participation constraints of the relationship, and add
appropriate symbols to the E-R diagram.
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Answer (Con’t)

a. Show how this entity set Purchase and its relationship to Book
would be represented on the E-R diagram.
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Answer (Con’t)

a. Show how this entity set Purchase and its relationship to Book
would be represented on the E-R diagram.
author title purchase Total
publisher
Date Amount
pubDate

number Book
Pages

condition cost

M 1 Purchase

Order
Number
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Answer (Con’t)

b. Stating any necessary assumptions, make a decision about the


cardinality and participation constraints of the relationship, and
add appropriate symbols to the E-R diagram.
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Answer (Con’t)

b. Stating any necessary assumptions, make a decision about the


cardinality and participation constraints of the relationship, and
add appropriate symbols to the E-R diagram.

We assume that each purchase must include at least one book, and may
include several.

We also assume that not all books are the result of a purchase, since the
collector can acquire books through gifts, inheritance, barter, or other
means.

We also assume a book is purchased at most once by the collector.

The 1 and M symbols and the single line and double line express these
constraints.
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase - Answer (Con’t)

author title purchase Total


publisher
Date Amount
pubDate

number Book
Pages

condition cost

M 1 Purchase

Order
Number
Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase + Seller Question

c. Assume there is another entity called Seller to be added to the


diagram with attributes name, address, phone, rating

The book collector makes purchases from many sellers, but each
purchase is made from one seller.

Add this entity and appropriate relationship(s) to the diagram.


Chapter 3: The Entity Relationship Model

Exercise 3.3 – Book + Purchase + Seller (Con’t)


Chapter 3: The Entity Relationship Model

Chapter 3 Team Assignment

Step 3.1- Make a list of all entities and their associated attributes.
Examine the data dictionary and cross-reference table and group the
appropriate attributes into entities.

Step 3.2 - Make a list of relationships to be represented and any


descriptive attributes for them.
Review the list of entities and determine the relationship between them.
Also indicate if the relationship is partial participation or total
participation.
Chapter 3: The Entity Relationship Model

Chapter 3 Team Assignment (Con’t)

Step 3.3 - Draw an E-R diagram to represent the enterprise.


Draw an E-R Diagram. First start with the entities that are needed for
your team assignment. Then identify the relationships and show how
they interact with the entities. Be sure to include the relationship
participation and the cardinality constraints

Step 3.4 - Update the data dictionary and list of assumptions as


needed.
Update the data dictionary based on the grouping from Step 3.1
Review the list of assumptions from Chapter 2 assignment and update
as needed.
Chapter 3: The Entity Relationship Model

Chapter 3 Individual Laboratory Assignment

Step 3.1 - Consider the entity set Employee with attributes:


empId, socSecNo, empName, jobtitle, and salary.

Step 3.1.a - Show how the Employee entity set and its attributes would be
represented on an E-R diagram.
Draw the entity Employee and include the attributes associated with the entity.

Step 3.1.b - Identify all candidate keys for the Employee entity set.
Write out the candidate keys.

Step 3.2.c - Identify the primary key for the Employee entity set and
underline it on the E-R diagram.
Write out the primary key and underline it on the E-R Diagram.
Chapter 3: The Entity Relationship Model

Chapter 3 Individual Laboratory Assignment (Con’t)

Step 3.1 - Consider the entity set Employee with attributes:


empId, socSecNo, empName, jobtitle, and salary.

Step 3.1.a - Show how the Employee entity set and its attributes would be
represented on an E-R diagram.
Draw the entity Employee and include the attributes associated with the entity.

Step 3.1.b - Identify all candidate keys for the Employee entity set.
Write out the candidate keys.

Step 3.2.c - Identify the primary key for the Employee entity set and
underline it on the E-R diagram.
Write out the primary key and underline it on the E-R Diagram.
Chapter 3: The Entity Relationship Model

Chapter 3 Individual Laboratory Assignment (Con’t)

Step 3.2 - Assume in the same enterprise, that there is a second entity set
called Project with attributes projName, startDate, endDate, and budget.

Step 3.2.a - Show how the Project entity set and its attributes and its
relationship to Employee would be represented on the E-R diagram.
Also, underline the primary keys for all entities on the E-R diagram.

Step 3.2.b - Assume you want to represent the number of hours an


employee is assigned to work on a project. Show how this would be
represented on the E-R diagram.

Step 3.2.c - Stating any necessary assumptions, make a decision about the
cardinality and participation constraints of the relationship between
Employee and Project, and add the appropriate symbols to the E-R
diagram.
CS 623 – Database Management Systems

Session 3 Agenda (Con’t)

Step 3.3 - Assume in the same enterprise, that there is a third entity set
called Department with attributes deptNo, deptName and mrgName.

Step 3.3.a - Show how the Department entity set and its attributes and its
relationship to Employee would be represented on the E-R diagram.
Also, underline the primary keys for all entities on the E-R diagram.

Step 3.3.b - Assume that each employee works for only one department.
Projects are not directly sponsored by a department. Show how this
would be represented on E-R diagram.

Step 3.2.c - Stating any necessary assumptions, make a decision about


the cardinality and participation constraints of the relationship
between Employee and Department, and add the appropriate symbols
to the E-R diagram.

You might also like