Beruflich Dokumente
Kultur Dokumente
Text: Chapter 2
Unit 2
Learning Goals
given a problem description, create an Entity-relationship
diagram with the correct entities and relationships that accurately model the problems data given a problem domain (description) that contains entities that depend on other entities, or inherit from other entities or have n-ary relationships with other entities, create an ER model that accurately represent them given a problem description, identify alternative representations of the problem concepts and evaluate the choices compare alternative ER models for the same domain and identify their strengths and weaknesses
Unit 2 2
Database Design
Consists of 6 steps: Requirements Elicitation & Analysis
common to all application designs; covered in CICS 505 Conceptual Database Design produces a high level description of data (semantic models) Logical Database Design converts conceptual design into a DB schema (logical schema) Schema Refinement restructuring to satisfy desirable properties (normalization) Physical Database Design deals with how the instances (actual data) will be stored on disk Application & Security Design general application design applications are restricted to only access data that they need
Unit 2 3
Information about these entities and relationships that should be stored in the database Integrity constraints or business rules that hold
For relational databases, the ER Model is used at this stage. The enterprise data is usually represented by an ER diagram.
Unit 2 4
distinguishable from other objects, whose data is important for the application. An entity is described using a set of attributes. E.g., all employees.
Unit 2
SIN
name
Addr
Employee
Keys
Distinguish entities A key is the minimal set of one or more
attributes which, taken collectively, identify uniquely an entity in an entity set. A superkey is a key plus zero or more other attributes in the entity set A primary key is the key chosen as the principal means to identify entities in an entity set Only primary keys are shown in ER diagrams (underlined attributes) Well discuss superkeys when we consider normal forms (for now, dont worry about them)
Street House #
City Address
Postal code
Province
Unit 2
Employee
supervisor subordinate
Reports_To
Relationship: Association among two or more entities. E.g., John works in Marketing department. Relationship Set: Collection of similar relationships. An n-ary relationship set R relates n entity sets E1 ... En; each relationship in R involves entities e1 E1, ..., en En o Same entity set could participate in different relationship sets, or in different roles in the same relatioship set. A relationship set may have descriptive attributes (like since). Degree or arity: # of entity sets in the relationship (binary, ternary, etc.)
Unit 2 7
1
Unit 2
and B above
many-to-many from A to B:
an entity in A is associated with any number of entities in B and vice versa e.g. A: students, B: courses
Unit 2 9
2
Key Constraints
The restriction imposed by a 1-to-1 and 1-to-many ratios are examples of key
constraint. A key constraint is shown with an arrow in the ER diagram. Important on insertions I.e.
since name ssn phone did dname budget
Employee
Manages
Department
or
Country Has Capital
Unit 2
10
tail of the arrow, then you know the relationship (and the other entities involved)
since name ssn phone did dname budget
Employee
Manages
Department
11
Participation Constraints
Participation : Indicates if all entities participate in the relationship. An entitys participation can be total (everyone participates) or
partial (some may not participate) A total participation is a participation constraint and it is shown with a thick line in ER diagrams
Important on deletions i.e. participation of Departments in Manages is total (thick line) o Every department must appear in some relationship in the Manages set since
name dname phone Employee ssn
did Manages
Department
budget
Works_In
Unit 2
since
12
Department
(many
to
many)
Manages
Department
(one
any line, arrow or not
Employee
Unit 2
to
many)
(one
to
many)
14
3, 4, 5
Weak Entities
A weak entity can be identified uniquely only by considering the primary
Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. Think of this as a belongs to relationship.
Weak entity sets and their identifying relationship sets are shown with thick lines.
name allowance
ssn
phone
pname
bday
Employee
Unit 2
has
Dependent
15
As in C++, or other PLs, attributes can be inherited. If we declare A ISA B, every A entity is also considered to be a B entity.
name
ssn
phone
Hourly_Emp
Contract_Emp
Unit 2
16
Specialization Types
Overlap constraints: Specializations can be:
Disjoint : a superclass entity may not belong to more than a single subclass Overlapping : subclasses may overlap
Unit 2
17
Aggregation
Used when we have to
grade
student
enrolls
section
Aggregation allows us to treat a relationship set as an entity set for purposes of participating in (other) relationships.
appears-in
report
enrolls is a distinct relationship, with a descriptive attribute. we can restrict each enrollment (and grade ) to appear in at most one report, if we want
Unit 2 18
7
Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? A lot of data semantics can (and should) be captured But some constraints cannot be captured in ER diagrams
o o
Unit 2
19
Unit 2
20
allow an employee to work in a department for two or more periods. We want to associate the same pair (employee, department) with more than one set of values for the descriptive attributes.
Solution: change
from
Works_In2
dname
budget
Department
from
Duration
to
21
is OK if a manager gets a separate discretionary budget for each dept. If a manager gets a budget that covers all managed depts?
dbudget
did
dname
budget Department
Manages2
name
ssn Employee phone
redundancy misleading
dbudget
ISA
since
did Manages3
Manager
If each policy is
Dependent
Bad design
Key constraint on Policies would mean policy can only cover 1 dependent!
Dependent
Beneficiary
Better design
policyid
Policies cost
23
than one ternary relationship. An example in the other direction: a ternary relation Drinks relates entity sets Person, Bar and Drink, and has descriptive attribute date. No combination of binary relationships is an adequate substitute:
P likes D, P visits B, and B provides D does not imply that P drinks D in B. Also, how would we record date?
Aggregation can be used instead of a ternary relation if need to impose additional constraints:
I.e. a person cannot have more than one drink in the same bar
24
Unit 2
Yields a high-level description of data to be stored Constructs are expressive, close to the way people think about their applications.
entities and relationships). Some additional constructs: weak entities, ISA relationships, and aggregation. Note: There are many variations on ER model.
Unit 2
25
Summary of ER (Cont.)
Several kinds of integrity constraints can be expressed in the
ER model: key constraints, participation constraints, and overlap/covering constraints for ISA relationships. Some foreign key constraints are also implicit in the definition of a relationship set.
Some constraints (notably, functional dependencies) cannot be expressed in the ER model. Constraints play an important role in determining the best database design for an enterprise.
Unit 2
26
Summary of ER (Cont.)
ER design is subjective. There are often many ways to
model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include:
entity vs. attribute entity vs. relationship binary or n-ary relationship whether or not to use ISA hierarchies whether or not to use aggregation
schema should be analyzed and refined further. Functional dependencies and normalization techniques are especially useful (see later).
Unit 2 27