663ae32024e04ae2f147cb9b DatabaseDesign
663ae32024e04ae2f147cb9b DatabaseDesign
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
6 / 25
Primary Keys
1. Each relation must have a primary key
2. Primary Key:
Combination of one or more attributes
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
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)
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
17 / 25
Generalization/Specialization Hierarchy
18 / 25
Generalization/Specialization Hierarchy
Relational Database Design Generalization /
Specialization Hierarchy 1/4
Superclass & subclasses mapped to relations
Superclass mapped to table
19 / 25
Generalization/Specialization Hierarchy
No superclass relation
2. Can use if
Subclass has many attributes
21 / 25
Generalization/Specialization Hierarchy
Relational Database Design Generalization / Specialization
Hierarchy 4/4
1. Superclass only mapped to relations
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)