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

663ae32024e04ae2f147cb9b DatabaseDesign

Uploaded by

rtwf0311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

663ae32024e04ae2f147cb9b DatabaseDesign

Uploaded by

rtwf0311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

SOFTWARE DEVELOPMENT PROJECT (SWP391)

Database Design Guides


Main Contents
• Overview
• Entity Classes & Relational Tables
• Primary Keys
• Foreign Keys
• Association Mapping
• Aggregation/Composition Hierarchy
• Generalization/Specialization Hierarchy
• Example Relational DB Design

2 / 25
Overview
• Relational database design (RDD) models information and data into a set
of tables with rows and columns. Each row of a relation/table represents a
record, and each column represents an attribute of data. The Structured
Query Language (SQL) is used to manipulate relational databases
• Steps in using COMET/UML
– Develop Software Requirements Model
– Develop Software Analysis Model
– Develop Software Design Model
• Design Overall Software Architecture (Chapter 12, 13)
• Design Distributed Component-based Subsystems (Chapter 12-13,15)
• Structure Subsystems into Concurrent Tasks (Chapter 18)
• Design Information Hiding Classes (Chapter 14)
• Architecture Design
• Design relational database (Chapter 15)
• Database Design
• Detailed Design

3 / 25
Overview
Main Inputs
• UC Specifications
• Entity Relationship Diagram (ERD)
• Entity Class Diagrams & Entity Attributes
• GUI/Screen Layout Design

4 / 25
Overview
Relational Database Design
Relational Database Design
1. Objective: Map static model to relational database
2. Each entity class from static model that needs to be stored in relational
database:
● Entity class maps to one (or more) relation(s) (table)
● Attributes mapped to columns of table
● Each object instance maps to a row of table
3. Relational Database Design:
● Primary keys
● Foreign keys for associations
● Association classes
● Aggregation/Composition Hierarchy
● Generalization/Specialization hierarchy

5 / 25
Entity Classes & Relational Tables
Entity Classes and Relational Tables

Account entity class Account relational table

6 / 25
Primary Keys
1. Each relation must have a primary key
2. Primary Key:
 Combination of one or more attributes

 Uniquely locates a row in relation

• E.g., Account Number is primary key of Account relation


• Account (Account number, Balance) – (underline = primary
key)

7 / 25
Foreign Keys
Relational Database Design Foreign Keys
1. Associations in relational databases:
Many-to-many association in static model
• Maps to a relation
One-to-one and one-to-many associations
• Use Foreign keys
2. Foreign key:
Primary key of one table that is embedded in another
table
Represents mapping of association between relations
into a table
Allows navigation between tables

8 / 25
Association Mapping
One-to-one or Zero-or-one Association 1/2
One-to-one association maps to:
• Foreign key in one of relations

Zero-or-one association maps to:


• Foreign key in optional relation

E.g., Customer Owns Debit Card

Static model:
• Customer (Customer Name, Customer Id,
Customer Address)
• Debit Card (Card Id, PIN, Expiration date,
Status, Limit, Total)
9 / 25
Association Mapping
One-to-one or Zero-or-one Association 2/2
One-to-one or Zero-or-one Association 2/2
1. Relational Database Design:
 Customer Id chosen as primary key of Customer
• Customer (Customer Name, Customer Id, Customer
Address)
 Card id chosen as primary key of Debit Card relation
2. Customer Id chosen as foreign key in Debit Card
3. Represents association between Customer and Debit
Card relations
4. Debit Card (Card Id, PIN, Expiration date, Status,
Customer Id)
 (underline = primary key, italic = foreign key)
10 / 25
Association Mapping
One-to-Many Association 1/2
One-to-many association maps
to:
• Foreign key in “many” relations
• E.g., Customer Owns Account
Static model:
• Customer (Customer Name,
Customer Id, Customer Address)
• Account (Account number,
Balance)
Relational Database Design:
• Primary key of “one” relation
(Customer) is chosen as foreign
key in “many” relation (Account)

11 / 25
Association Mapping
One-to-Many Association 2/2
One-to-Many Association 2/2
Relational Database Design:
Customer Id chosen as primary key of
Customer relation
• Customer (Customer Name, Customer Id,
Customer Address)
Account Number is chosen as primary key of
Account relation
Customer Id is foreign key in Account relation
• Account (Account Number, Balance, Customer Id)
12 / 25
Association Mapping
Static Model Association Class 1/2
1. An association class models association between
two or more classes and is typically used to
represent a many-to-many association
2. Association class is mapped to associative
relation
3. Associative relation
 Relation to represent association between two or
more relations
 Primary key of associative relation
• Concatenated key
• Formed from primary key of each relation that
participates in association

13 / 25
Association Mapping
Static Model Association Class 2/2
Static Model Association Class 2/2
1. E.g., Hours association class:
 Represents association between Project and Employee classes
 Mapped to Associative relation Hours
2. Static model:
 Project (Project id, Project name)
 Employee (Employee id, Employee name, Employee address)
 Hours (Hours Worked)
• Hours Worked is attribute of association

14 / 25
Association Mapping
Relational DB Design Associative Relation
1.Relational Database Design
 Project (Project id, Project name)
 Employee (Employee id, Employee name,
Employee address)

2.Project id and Employee id


 Form concatenated primary key of Hours relation
 Also foreign keys
• Hours (Project id, Employee id, Hours worked)

15 / 25
Aggregation/Composition Hierarchy
Static Model Aggregation/Composition Hierarchy
Whole/part relationship
 Aggregate/Composite (whole) class is mapped to

relation
 Each part class is mapped to relation

 Primary key of aggregate/composite relation

 All of primary key of component relation


 1-1 aggregation
 Part of primary key of component relation
 1-n aggregation
 Foreign key
 If not needed to uniquely identify component relation
16 / 25
Aggregation/Composition Hierarchy
Relational Database Design Aggregation /
Composition Hierarchy
1. E.g., Static Model:
 Department IS PART OF College
 Admin Office IS PART OF College
 College (College name)
 Admin Office (Location)
 Department (Department name,
Location)
2. Relational Database Design:
 Primary key of aggregate relation = College
name
 College (College name)
 Admin Office (College name, Location)
 Department (Department name, College
name, Location)

17 / 25
Generalization/Specialization Hierarchy

Static Model Generalization / Specialization


Hierarchy
Three alternative mappings from Generalization

/ Specialization Hierarchy to relational database


 Superclass & subclasses mapped to relations
 Subclasses only mapped to relations
 Superclass only mapped to relation

18 / 25
Generalization/Specialization Hierarchy
Relational Database Design Generalization /
Specialization Hierarchy 1/4
Superclass & subclasses mapped to relations
 Superclass mapped to table

• Discriminator is attribute of superclass table


 Each subclass mapped to table
 Shared id for primary key
• Same primary key in superclass and subclass tables
 Clean and extensible
 However, superclass / subclass navigation may be
slow

19 / 25
Generalization/Specialization Hierarchy

Relational Database Design Generalization /


Specialization Hierarchy 2/4
1. Superclass & subclasses mapped to
relations
2. E.g.: Account Generalization /
Specialization Hierarchy
3. Static Model
 Superclass: Account (Account
number, Balance)
 Subclass: Checking Account (Last
Deposit Amount)
 Subclass: Savings Account (Interest)
4. Relational Database Design
 Account (Account number, Account
Type, Balance)
 Checking Account (Account Number,
Last Deposit Amount)
 Savings Account (Account Number,
20 / 25 Interest)
Generalization/Specialization Hierarchy
Relational Database Design Generalization / Specialization
Hierarchy 3/4
1. Superclass only mapped to relations
 Map each subclass to relation

 No superclass relation

 Superclass attributes replicated for each subclass table

2. Can use if
 Subclass has many attributes

 Superclass has few attributes

 Application knows what subclass to search

21 / 25
Generalization/Specialization Hierarchy
Relational Database Design Generalization / Specialization
Hierarchy 4/4
1. Superclass only mapped to relations

2. All subclass attributes brought up to superclass table


 Discriminator is attribute of superclass table
 Each record in superclass table uses attributes relevant to
one subclass
 Other attribute values are null

3. Can use if
 Superclass has many attributes
 Subclass has few attributes
 Only two or three subclasses

22 / 25
Example Relational DB Design 1/2
Example of Relational Database Design 1/2

23 / 25
Example Relational DB Design 2/2
Example of Relational Database Design 2/2
1. Banking System static mode
2. Bank Information (underline = primary key, italic = foreign
key):
–Bank (bankName, Bank Address, bankId)
–ATM Info (bankId, ATMId, ATM Location, ATM Address)
–Customer (customerName, customerId, customerAddress)
–Debit Card (cardId, PIN, startDate, expirationDate, status, limit,
total, customerId)
–Checking Account (accountNumber, accountType, balance,
lastDepositAmount)
–Savings Account (accountNumber, accountType, balance,
interest) Card Account (cardId, accountNumber)
–Customer Account (customerId, accountNumber)

–Assumption: Account type is determined from account number


24 / 25

You might also like