CS143: Programming in C++

advertisement
CS 3630
Database Design and Implementation
Assignment1
2
Database Design
Relational Database
A collection of normalized tables/relations.
3
The Three Level ANSI-SPARC Architecture
DBTG (Data Base Task Group)
Appointed by the Conference on Data Systems and
Languages in 1971
Two level approach
SPARC: Standards Planning And Requirement Committee
ANSI/X3/SPARC, 1975
Based on IBM's view
For any database system
Data Independence.
4
The Three Level ANSI-SPARC Architecture
External Level
View 1
View 2
Conceptual Level
Conceptual
schema
Internal Level
Internal
schema
…
View 3
Database
5
Phases of Database Design
• Conceptual Database Design
Understanding the data
• Logical Database Design
Normalization
• Physical Database Design
We ignore it.
6
Conceptual Database Design
• Users' views
• Understanding of the meaning of the data
Common Sense
Business rules
Do not assume anything
Students without any classes at UWP
Classes without any students
• E-R Model
Formal document to specify the requirements
Entity and Relationship
• Independent of the target data model (relational, OO).
7
Logical Database Design
• Designer's view
• Based on the target data model
Relational
• Normalization.
8
Physical Database Design
• Base relations and constraints
• File Organization and Storage Structure
(Appendix C)
• Others.
9
Conceptual Database Design
E-R Model (Ch 11)
High level conceptual data model
Top-Down approach
Widely used
but not the only model
UML (Unified Modeling Language)
Draw ER diagrams.
10
Entity Types
A group of objects with the same properties,
which are identified by the enterprise as
having an independent existence.
Similar to Class in OOP
Class is an implementation of Entity.
11
Physical Existence
•
•
•
•
•
Branch
Staff
PropertyForRent
Client
Owner
• Customer
• Product
• Supplier.
12
Conceptual Existence
• Viewing
• Inspection
• Sale
• Work Experience.
13
Entity Occurrence
A uniquely identifiable object of
an entity type.
Class and Object.
14
Diagrammatic Representation of
Entity Types
• Rectangle
• The first letter of the entity name is upper case
Branch
Staff
15
Relationship Types
(Not Relation)
A set of meaningful associations among entity
types.
Branch
Staff
Owner
Has
Staff
Manages Branch
Owns
PropertyForRent.
16
Relationship Occurrence
A uniquely identifiable association, which
includes one occurrence of each participating entity type
Example
Branch B003 has staff SG5
Owner O321 owns property P1045.
17
Semantic Net for
Relationship Occurrence
r1
B003
SG5
r2
SG37
B007
Branch
r3
SA9
Has
Staff
18
Diagrammatic Representation of
Relationship Types
Directed line with the relationship name
Branch
Has
Staff
19
Degree of Relationship Type
The number of participating entity types in a
relationship
Binary
Ternary
Quaternary
20
A Ternary Relationship
Branch
Registers
Staff
Client
21
A Quaternary Relationship
A solicitor arranges a bid on behalf of a buyer
supported by a financial institute.
Solicitor
Buyer
Arranges
Bank
Bid
22
Recursive Relationship
A relationship type where the same entity type
participates more than once in different roles.
Staff (Supervisor) supervises Staff (Supervisee)
Roles
Supervisor
Supervisee.
23
Recursive Relationship
Supervises
Supervisor
Supervisee
Staff
24
Multiple Relationships between the
Same Entity Types
Branch Has
Staff (Staff Members)
Staff (Manager) Manages Branch.
25
Multiple Relationships between
Entity Types
Manages
Branch
Staff
Has
26
Relationship or Entity?
• Viewing
As Entity in DreamHome example
• Could be a Relationship
Client Views PropertyForRent
• It can be treated either way
The final design will be the same.
27
Attributes of an Entity Type
A property of an entity type or a relationship type.
Similar to the fields of a class
PropertyForRent
propertyNo
address (street, city, state, zipcode)
type
rooms
rent
...
28
Attributes of a Relationship
Client
Views
PropertyForRent
Views
Date
Comment
29
Domain of Attribute
The set of allowable values for one or more
attributes
PropertyForRent
propertyNo: String (size)
type: ‘Flat’, ‘House’
rooms: integer, 1 - 15
rent: integer, 150 – 1000
...
30
Simple and Composite Attribute
Simple attribute
An attribute composed of a single component
position
salary
GPA
Composite attribute
An attribute composed of multiple components
name : firstName, lastName, middle
address: street, city, state, zipcode
DOB : year, month, day
workExperience: organization, position, start, end.
31
Single-valued and Multi-valued
Attribute
Single-valued: An attribute that holds a single value for each
occurrence of an entity type
branchNo
name
DOB
GPA
The value could change from time to time, but one value at
any given time.
Multi-valued: An attribute that can hold multiple values for
each occurrence of an entity type
phoneNo
studentMajor
workExperience.
32
Composite and Multi-valued
Attribute
Composite attribute could be single-valued or multivalued
name: single-valued
workExperience: multi-valued
Multi-valued attribute could be simple or composite
phoneNo: simple
workExperience: composite.
33
Composite and Multi-valued
Attribute
Simple attribute could be single-valued or multivalued
salary: single-valued
major: multi-valued
Single-valued attribute could be simple or composite
salary: simple
DOB: composite.
34
Derived Attribute
An attribute that represents a value that is
derivable from the values of a set of related
attributes, not necessarily in the same entity
type.
Age
Total Number of staff members
Deposit of Lease is twice the rent.
35
Required or Optional Attribute
Required Attributes
studentID
Name
DOB
...
Optional Attributes
phoneNo
Major
...
36
An Eneity Type Example
Staff
staffNo
name
address
: composite (first, last, middle)
: composite (street, city, state,
zipcode)
phoneNumber : multi-value
salary
workExperience: multi-value
composite (organization,
position, start, end)
...
37
A Relationship Example
Client
Views
PropertyForRent
Date
Comment
38
Assignment 2
Due beginning of class, Friday, Feb 5
39
Quiz1
Wednesday
40
Download