Upload
duongdien
View
233
Download
3
Embed Size (px)
Citation preview
Requirement Analysis &Requirement Analysis &Conceptual Database DesignConceptual Database Design
Problem analysisEntity Relationship notationIntegrity constraintsGeneralization
1.2
FU-Berlin, D
BS I 2006, Hinze / Scholz
Introduction: LifecycleLifecycle
Requirement analysis -> Text
Conceptual Design -> ER-Model
Name
SID
KID
Name
Dauer
Name DID
EmailVName VName
Studentin
Kurs
Dozentin
anmelden
voraussetzen
Vorgänger Nachfolger
(1,*)
(0,*)
(0,*) (0,*)
halten
(1,*)
(1,1)
Administration
Logical Schema DesignCREATE TABLE Studentin(SID INTEGER PRIMARY KEY,VName CHAR(20)Name CHAR(30) NOT NULL,Email Char(40));
CREATE TABLE Kurs(KID CHAR(10) PRIMARY KEY,Name CHAR(40) NOT NULL,Dauer INTEGER);
CREATE TABLE Anmelden(SID INTEGER PRIMARY KEY FOREIGN KEY REFERENCES Studentin (SID),KID INTEGER PRIMARY KEY FOREIGN KEY REFERENCES Studentin (KID));
-> Database schema
Physical Schema Design -> Access paths
1.3
FU-Berlin, D
BS I 2006, Hinze / Scholz
Introduction: Database Design TerminologyIntroduction: Database Design Terminology
Different from Software Engineering !Database Design
process of defining the structure of a database layers of abstraction: Conceptual, logical, physical level
Includes "Analysis" and "Design" from SE
Database Software EngineeringRequirements RequirementsConceptual modelingLogical modelingPhysical modeling
AnalysisDesign
1.4
FU-Berlin, D
BS I 2006, Hinze / Scholz
Requirement AnalysisRequirement Analysis
Customer communication!
Identify essential "real world" information Remove redundant, unimportant detailsClarify unclear natural language statementsFill remaining gaps in discussionsDistinguish data and operations
Requirement analysis & Conceptual Design aims at focusing thoughts and discussions !
1.5
FU-Berlin, D
BS I 2006, Hinze / Scholz
Requirement Analysis: ExampleRequirement Analysis: Example
“I’m the owner of a medium size video store. We have over 10.000video tapes that we need to keep track of. Since a few weeks, we also have DVDs. Each of our video tapes has a tape number. For each movie, we need to know its title and category (e.g. comedy, suspense, drama, action, or SciFi), director and year. Yes, we do have multiple copies of many of our movies. We give each movie a specific id, and thentrack which movie a tape contains.
A tape may be either Beta or VHS format. We always have at leastone tape for each movie we track, and each tape is always a copy of a single, specific movie. Our tapes are adapted to the movielengths, so we don’t have any movies which require multiple tapes. The movies are stored on shelf according to their category sorted by movie title. We are frequently asked for movies starring specific actors, John Wayne and Katherine Hepburn are always popular. So we’d like to keep track of the star actors appearing in each movie.....
1.6
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: ExampleConceptual Design: Example
.... Not all of our movies have star actors. Customers like to know each actor’s “real” birth name and age. We track only actors whoappear in the movies in our inventory. We have lots of customers. We only rent videos to people who havejoined our “video club”. To belong to our club, they must have good credit. For each club member, we’d like to keep their first andlast name, current phone number, and current address. And, of course each club member has a membership number. Then we need to keep track of what video tapes each customer currently has checked out. A customer may check out multiple video tapes at any given time. Rentals are for one or more days, each movie with an individual price per day. Furthermore we additionally charge 1 $ per beta format tape, 2 $ for a DVD andanother $ for movies longer than 2 hours. Maximum rental time is 4weeks. The customer gets a bill with movie titles, individual prices and total amount, when he /she returns movies."
1.7
FU-Berlin, D
BS I 2006, Hinze / Scholz
Requirement Analysis: ExampleRequirement Analysis: Example
Note: what is important depends on the applications Essential information
customers, tapes, movies, ...movies have many copiestape (or DVD) contains exactly one moviecustomers have customer identification (id) four weeks maximal rental time…
Redundant, unimportant details"...DVDs since a few weeks“"... John Wayne..“Names of the categories (but categories are important!) Tapes on shelf (since we don't design a tape robot)…
1.8
FU-Berlin, D
BS I 2006, Hinze / Scholz
Requirement Analysis: ExampleRequirement Analysis: Example
Clarify unclear statements Video club: admission / annual fee? Charge per tape: is price for one day the minimum?...
Fill gaps Any discounts?...
Distinguish data/operationsProcessing a billBecoming a member of the club …
1.9
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Modeling primitives Conceptual Design: Modeling primitives
Entitysomething which exists Examples: tape, movie
Attributeproperty of an entityExamples: tape has id, movie has title
Relationship: connects two or more entities Examples: tape contains a movie.
Attributes have valuesExample: “John Wayne is starring”Not modelled!
Tape
contain
id
Movie
Tape
titleMovie
id
Tape
title
Movie
Important terms
1.10
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Structuring the problemConceptual Design: Structuring the problem
Modelling / Conceptual Designtypically: Entity-Relationship-Model, data-oriented1976 introduced by P.P. Chen (Peter P. Chen: The Entity-Relationship Model - Toward a Unified View of Data. TODS 1(1): 9-36, 1976)
sometimes: UML (problematic!)
StudentSID: NumberName: StringFName: StringEmail: String
LectureLID: NumberTitle: Stringhours: Number
attend
Lecture
attend
Name
LID
Title
hours
FNameStudent
SID
1.11
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: EConceptual Design: E--R notation R notation
Entities & Attributes:
Entities have identifying (or key) attributes or sets of attributes
Tape
id
keyMovie
title director category
These attributes together identify a movie
Entity
attribute attribute attribute
1.12
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: EConceptual Design: E--R notation R notation
Relationships
Always have a nameDo not have a key!Not always reflected by the relationship namesee example: "rents" is equivalent to "is-rented_by"
Entity_1 Entity_2relationship
Customer rents Tape
attribute
attribute
attribute
attribute
1.13
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: ExampleConceptual Design: Example
“[…] We have […] video tapes that we need to keep track of. Since a few weeks, we also have DVDs. Each of our video tapes has a tape number. For each movie, we need to know its title and category, director and year. We do have multiple copies of many of our movies. We give each movie a specific id, and then track which movie a tape contains. A tape may be either Beta or VHS Format. We always have at least one tape for each movie we track, and each tape is always a copy of a single, specific movie. Our tapes are adapted to the movie lengths, so we don’t have any movies which require multiple tapes. The movies are stored on shelf according to their category sorted by movie title. We are frequently asked for movies starring specific actors. […] Customers like to know each actor’s “real” birth name and age. We track only actors who appear in the movies in our inventory. […]Rentals are for one or more days, each movie with an individual price per day. Furthermore we additionally charge 1 $ per beta format tape, 2 $ for a DVD and another $ for movies longer than2 hours.” [abbreviated]
1.14
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: ExampleConceptual Design: Example
MovieTape hold
Actor
play
Format
belong_to
chargebirthday
name stage_name
real_name
directortitlecategory year
id
Price_per_day
id
length
(without customers)
1.15
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: EConceptual Design: E--R notationR notation
Multiple relationships
Recursive relationships
Lecture
require
predecessor successor
Person
have
parent child
Lectureattend
Student
hold
role name
1.16
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: EConceptual Design: E--R notationR notation
Relationships with attributes
Different semantics in separate entity:
Lecture Lecturerhold
rating
Lecture Lecturerhold
rating
Lecture_datebelong_to
1.17
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Integrity constraintsConceptual Design: Integrity constraints
Integrity constraints (=Invariants)Database must always meet these invariants
Explicit state restrictions from requirements Examples:
"There is always at least one tape for each movie …, and each tape is always a copy of a single, specific movie”"Not all of our movies have star actors"
Implicit invariants commonExamples:
Tape cannot be loaned by more than one customer a timeActor may be starring in more than one movie
Important concept
1.18
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Integrity constraintsConceptual Design: Integrity constraints
Constraints:
Attribute restrictionsAttribute contain at most one value: unstructured attribute restriction of E-R M.Key attributes are unique
Attribute must / may have a valuee.g., movie must have title,
director is not necessarily known Value may be restricted e.g., movies are made after 1900 : movie.year > 1900Special restrictions not in E-R model!
Attribute restrictionsCardinality restrictions
1.19
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Integrity constraintsConceptual Design: Integrity constraints
Cardinality restrictions# entities-instances in relationship (UML: multiplicity)
Moviehold
Tape
1:None movie on a tape
Movieplay
Actor
N:Mseveral actors in many movies
Personown
drivers license
1:1one licence per driver
Examples: one movie on a tape, tape loaned by at most one customer at a time, #rented tapes per customer ≥ 0
1.20
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: CardinalitiesConceptual Design: Cardinalities
Simple Notation E1 R E2k1 k2
Tape rent CustomerN 1
“N tapes are rented by 1 customer”
E1 R E2(min1,max1)
(min2,max2)
Min-Max Notation:
Tape rent Customer(0,1) (0,*)
“Each tape is rented by 0-1 customers”“Each customer has rented 0-N tapes”
1.21
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: CardinalitiesConceptual Design: Cardinalities
1:1 relationship
1:N relationship
N:M relationship
person have driversLicence(0,1) (1,1)
Movie hold Tape(1,*) (1,1)
Lecture hold Lecturer(1,1) (0,*)
User_account has emailMessage(0,*) (1,*)
Do not mix notations!
1.22
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Semantics N:M, (Conceptual Design: Semantics N:M, (min,maxmin,max))
R is 1:N ⇔ R is a partial function R: E2 → E1⇔ for all extensions of R ∀e2 ∈ E2:
|{e1 | e1 ∈E1 ∧ (e1,e2) ∈ R }| ≤ 1
R is 1:1 ⇔ E2 → E1 is a injective partial functionR is M:N ⇔ R is a relation, but not a function
Important conceptLet R ⊆ E1 x E2 be a relationship between entity sets E1 and E2
(R,E1) has (min1, max1) ⇔ for all extensions of R and for all x ∈E1
min1 ≤ |{y| y ∈ E2 ∧ (x,y) ∈ R }| ≤ max1
(R,E2) has (min2, max2)⇔ for all extensions of R and for all y ∈E2
min2 ≤ |{x | x ∈ E1 ∧ (x,y) ∈ R }| ≤ max2
1.23
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: ExampleConceptual Design: Example
MovieTape hold
Actor
play
Format
belong_to
chargebirthday
name stage_name
real_name
directortitlecategory year
id
Price_per_day
id
length
(without customers)
(1,1)
(1,1)
(0,*) (1,*)
(0,*)
(1,*)
1.24
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: notational overviewConceptual Design: notational overview
10 .. 1 0 ..*
*0 .. k
1 ..*k..jk
UML
11N or MN or ME-RM1:N
(1,1)(0,1)(0,*)(1,*)E-RM
(min,max)
mandatory/ single
optional/ single
optional/ multiple
mandatory/ multiple
k,j,N,M are natural numbers
More notations in use, e.g., oracle-special notation...
1.25
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Weak entitiesConceptual Design: Weak entities
Existentially dependent entitiesNot globally identifiableExample:
Notation:
min2 = 1 : at least one e1 for each e2, otherwise e2 could not be identified
max2 = 1
Building has Room(1,*) (1,1)
id
E1 R E2(min1,max1) (min2, max2)
id
1.26
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Weak entitiesConceptual Design: Weak entities
Example: Movies and their scenes
Example: Order and Delivery
Movie Scene(0,*) (1,1)
has
has(1,*) (1,1)
Item IidOrder
Delivery Did
contains
Oid
(1,1)
(1,*)
1.27
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Weak entitiesConceptual Design: Weak entities
Modelling decision:
or
employee has child(0,*) (1,1)
eid
cid
employee has child(0,*) (1,1)
eid
cid
Advantages and disadvantages?
1.28
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Temporal dataConceptual Design: Temporal data
1. Condition: tape only rented by one customer at the same time:
2. Condition: tape rented by many customers one after the other
customer videotaperent(0,*) (0,*)
customer
videotape
cid
vid
from
untilrentalhas
is_in
(0,*)
(0,*)
(1,1)
(1,1)
customer videotaperent(0,*) (0,1)
cid vid
from until
1.29
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: ExampleConceptual Design: Example
Movie
Tape
hold
Actor
play
First_name
birthday
Address
Telephone
Last_name
stage_name
real_name
directortitle category
yearid
Customer
Mem_no
Price_per_day
id
Format
belong_to
charge
namelength
Rentalfrom
is_in
have
(1,1)
(1,1)
(0,*)
(1,*)
(0,*)
(1,*)
(0,*)(1,1)
(1,1)
(0,*)
until
1.30
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Conceptual Design: nn--aryary relationshipsrelationships
Example:Lecturer recommends textbook for lecture
Cardinalities:A particular lecturer recommends zero or more "(textbook,lecture) pairs" For each lecture at least one textbook is recommended by lecturershere, (min,max)-constraints not very expressive
Lecturer recommend Textbook(0,*) (1,*)
Lecture
(1,*)
1.31
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Conceptual Design: nn--aryary relationshipsrelationships
1:N notation in n-ary relationships Remember: R is 1:N ⇔ R is function R:E2 → E1
Generalization: R: E1 x…x Ej-1 x Ej+1 x…x En → Ej
recommend: Textbook x Lecturer → Lecturerecommend: Textbook x Lecture → Lecturer
E1 E21 NR
Lecturer recommend Textbook1 N
Lecture
M
1.32
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Conceptual Design: nn--aryary relationships relationships (Example 2)(Example 2)
Student is allowed to have only one topic for each Prof.Student is allowed to have only one Prof. for each topicProfs. are allowed to use the same topic againA topic can be used be used by many Profs., but for different students
Prof. attend Topic1 1
Student
M
1.33
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Conceptual Design: nn--aryary relationshipsrelationships
N-ary relationships expressed by binaries
1. Connect pairs of entities
Less constraints expressible!
2. New “central” entity, binary relationships to old ones
Lecturer Lecture
Textbook
Lectureplan ……
…
Lecturer LectureTextbook ……
1.34
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: GeneralizationConceptual Design: Generalization
Consider lecturing students:similar objects in different entitiesRedundancy ⇒ errors!
Generalization (specialization) helps
LectureattendStudent
hold2
Lecturer hold1
SID Email
FName
Name
Namelid Email
FNameContract
LID
title
hours
1.35
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: GeneralizationConceptual Design: Generalization
Lecture
attend
Student
hold
LecturerSID
pid
Contract
LID
title
hours
Person
is-a is-a
Name
FName
DB Interpretation of Generalization differs from OO!instances of Student and Lecturer also instances of PersonStudent ⊆ Person, Lecturer ⊆ Person
1.36
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: GeneralizationConceptual Design: Generalization
OO-interpretation: Instances of A, B and C different but share some attributes
DB interpretation: Instances of B and C also instances of A: B ⊆ A and C ⊆ AKey-inheritance"is-a" different from ordinary relationships
Special cases: Disjoint specialization: Instances of B and C are disjointComplete specialization: A = B ∪ C, no extra tupel in A
B C
A
is-a is-a
1.37
FU-Berlin, D
BS I 2006, Hinze / Scholz
Conceptual Design: Short summaryConceptual Design: Short summary
E-R ModellingStandard semi-formal language for conceptual modellingDifferent notations: we use E-R and (min,max)
Important termsEntity (type, set): set of objects with the same attributesAttribute: property of an entity, at most one value per attribute. Relationship (type): association between entity typesRole: name of one side of relationship Cardinality (multiplicity): number of entity objects that participate in relationship Weak entity: existentially dependent entityGeneralization