Download Lecture 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Data model wikipedia , lookup

Relational algebra wikipedia , lookup

Data vault modeling wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
CPSC 603 Database Systems
Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E.
Lecture 2
Introduction to a First Course in Database Systems
CPSC 603 Database Systems
Relational Models
Relational models uses a collection of tables to
represent both data and relationships among those data
Controlling Redundancy
Redundancy  storing the same data multiple times
=> leads to several problems!!!
1. Need to perform a single logical update - such as
entering data on a new student - multiple times
- once for each file where student data is
recorded => duplication of effort
2. Storage space is wasted when same data is stored
repeatedly
3. Files that represent the same data may become
Controlling Redundancy
Inconsistent => may happen because an update is
applied to some of the files but not to others
Three Aspects of Studying
DBMS’s
• Modeling and Design of Databases
– Allows exploration of issues before committing
to an implementation
• Programming:Queries and DB operations
like update
– SQL = “intergalactic dataspeak”
• DBMS implementation
Entity/Relational Model
Diagrams to represent designs
• Entity like object,= “thing.”
• Entity set like class - set of “similar” entities
/ objects.
• Attribute = property of entities in an entity
set, similar to fields of a struct.
Entity/Relationship Model
Diagrams
In Diagrams:
Entity set  rectangle
Attribute  oval
ID
Name
Phone
Students
Height
Relationships
• Connect two or more entity sets (E.S.)
• Represented by diamonds.
Students
Courses
Taking
Relationship is taking
Relationship between Students and Courses
Students take Courses
Relationship Sets
• Think of the “value” of a relationship set as a table.
– One column for each of the connected entity sets
– One row for each list of entities, one from each set, that
are connected by the relationship
Relationship Set
Students
Sally
Sally
Joe
………
Courses
CPSC 310
CPSC 603
CPSC 420
………….
One column for each of the connected entity sets
1) Students 2) Courses
One row for each list of entities 1. (Sally,…) and 2. (CPSC 310, ….)
Multiway Relationships
Binary Relationships Suffice
• However, there are some cases where three
or more E.S. must be connected by one
relationship
• Example: Relationship among students,
courses, TA’s. Possibly, this E/R diagram
shown next will be O.K.
Multiway Relationship
Students, Courses, TA’s
Students
Taking
Courses
Assisting
TAs
Multiway Relationships
• This works with CPSC 310(603), because
each TA is a TA of all students. Connection
student-TA is only via the course
• But what if students were divided into
sections, each headed by a TA?
– Then, a student in CPSC 310 would be related
to only one of the TA’s for CPSC 310. Which
one?
• Need a 3-way relationship to tell
Elements of the E/R Model
continued (Chapter 2 of Text)
Entity Types, Entity Sets,Keys, and Value Sets
Entity Types and Entity Sets
A database usually contains groups of entities
that are similar
For Example:
A company employing hundreds of employees
may want to store similar information
concerning each of the employees.
Entity Type
• An Entity Type defines a collection (set) of
entities that have the same attributes
• Each Entity Type in the database is
described by its name and attributes
Key Attributes of an Entity Type
An important Constraint on the entities of an entity
type is the key or uniqueness constraint on attributes
An entity type usually has an attribute whose vaues are
distinct for each individual entity in the collection
=> such an attribute is called a key attribute
Key Attributes of an Entity Type
For the Person Entity
==> A typical Key Attribute is SSN#
Key Attributes of an Entity Type
In the ER Diagrammatic notation, each Key
Attribute has its name underlined inside the Oval
SSN
Entity
Attribute
EMPLOYEE
Weak Entity Sets
Sometimes an E.S. E’s key comes not
(completely) from its own attributes, but from
the keys of one or more E.S.’s to which E is
linked by a supporting many-to-one
relationship
• Called a weak E.S.
• Represented by putting a double rectangle
around E and a double diamond around
each supporting relationship
Weak Entity Sets
Sometimes an E.S. E’s key comes not
(completely) from its own attributes, but from
the keys of one or more E.S.’s to which E is
linked by a supporting many-to-one
relationship
• Many-one-ness of supporting relationship
(includes 1-1) essential
– With many-many, we wouldn’t know which
entity provided the key value.
• “Exactly one” also essential, or else we
might not be able to extract key attributes
by following the supporting relationship
Entity-Relationship Diagram
A Movie Database
Title
Year
Name
Movies
Stars-In
Address
Stars
Name
Owns
Length
filmType
Studios
Address
Multiway Relationships
Example 2.5
In Fig. 2.4 is a relationship Contracts that involves a
studio, a star, and a movie. This relationship
represents that a studio has contracted with a particular
star to act in a particular movie.
Stars
CONTRACTS
Studio
Movie
Roles in Relationships-Fig. 2.5
• It is possible that one entity set appears two or more
times in a single relationship
– If so, we draw as many lines from the relationship to the
entity set as the entity appears in the relationship. Each
line to the entity set represents a different role that the
entity set plays in the relationship
Original
Movie
Sequel-of
Sequel
Roles in Relationships-Fig. 2.5
• In Sequel-of the relationship is between the
entity set Movies and itself
Original
Sequel-of
Movies
Sequel
Next Lecture
•
•
•
•
•
Database Design Principles
Modeling of Constraints
Weak Entity Sets
Summary of Chapter 2
Relational Data Model