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

Chapter 2

The document discusses database design. It begins by describing common database entities like customers, salespeople, orders, and order items. It then covers conceptual, logical, and physical design stages. The main topics are developing conceptual data models using entity-relationship diagrams and UML class diagrams, logical relational database design using normalization, and physical design including storage and performance aspects. Association types like one-to-one, one-to-many, and many-to-many relationships are also discussed.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Chapter 2

The document discusses database design. It begins by describing common database entities like customers, salespeople, orders, and order items. It then covers conceptual, logical, and physical design stages. The main topics are developing conceptual data models using entity-relationship diagrams and UML class diagrams, logical relational database design using normalization, and physical design including storage and performance aspects. Association types like one-to-one, one-to-many, and many-to-many relationships are also discussed.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Database Management Systems

Chapter 2
Database Design

1
Database System Design
Customer(CustomerID, Name, Address, …)
SalesPerson(EmployeeID, Name, Commission, … )
Order(OrderID, OrderDate, CustomerID, EmployeeID, … )
OrderItem(OrderID, ItemID, Quantity, Price, … )
Item(ItemID, Description, ListPrice, …)

User views Conceptual Implementation Physical


of data. data model. (relational) data
data model. storage.

List of nicely-behaved Indexes and storage


Class diagram that
tables. Use data methods to improve
shows business entities,
normalization to derive performance.
relationships, and rules.
the list.

2
The Need for Design
• Goal: To produce an information system that adds value for the user
• Reduce costs
• Increase sales/revenue
• Provide competitive advantage
• Objective: To understand the system
• To improve it
• To communicate with users and IT staff
• Methodology: Build models of the system

3
Designing Systems
• Designs are a model of existing & proposed systems
• They provide a picture or representation of reality
• They are a simplification
• Someone should be able to read your design (model) and describe the features
of the actual system.
• You build models by talking with the users
• Identify processes
• Identify objects
• Determine current problems and future needs
• Collect user documents (views)
• Break complex systems into pieces and levels
4
Design Stages
• Initiation • Physical Design
• Scope • Table definitions
• Feasibility • Application development
• Cost & Time estimates • Queries
• Forms
• Requirements Analysis
• Reports
• User Views & Needs • Application integration
• Forms
• Data storage
• Reports
• Security
• Processes & Events
• Procedures
• Objects & Attributes
• Implementation
• Conceptual Design
• Training
• Models
• Purchases
• Data flow diagram
• Entity Relationships • Data conversion
• Objects • Installation
• User feedback • Evaluation & Review

5
Initial Steps of Design
1. Identify the exact goals of the system.
2. Talk with the users to identify the basic forms and reports.
3. Identify the data items to be stored.
4. Design the classes (tables) and relationships.
5. Identify any business constraints.
6. Verify the design matches the business rules.

6
Unified Modeling Language
A relatively new method to design systems. (UML)
Contains several types of diagrams:

Contains several types of diagrams:

Cla ss dia gr a m Sh ows t h e st a t ic m odel of t h in gs t h a t exist a n d t h eir


r ela t ion sh ips.
U se ca se dia gr a m Sh ows h ow a ct or s will u se t h e fu n ct ion a lit y of t h e syst em .
Sequ en ce dia gr a m Repr esen t s a n in t er a ct ion or set of m essa ges exch a n ged
a m on g object s. Specifica lly sh ows in t er a ct ion over t im e.
Colla bor a t ion dia gr a m Sh ows t h e in t er a ct ion a n d lin ks a m on g object s. Does n ot sh ow
t im e a s a sepa r a t e dim en sion . It is a pr ocess dia gr a m .
St a t ech a r t dia gr a m s Sh ows t h e sequ en ce of st a t es t h a t a n object goes t h r ou gh
du r in g it s lifet im e in r espon se t o st im u li.
Im plem en t a t ion dia gr a m s Sh ows t h e st r u ct u r e of t h e code or of t h e r u n -t im e m odu les.

The class diagram is the most important for database design.

7
Definitions
Entity: Something in the real world that we wish to describe
or track.
Class: Description of an entity, that includes its attributes
(properties) and behavior (methods).
Object: One instance of a class with specific data.
Property: A characteristic or descriptor of a class or entity.
Method: A function that is performed by the class.
Association: A relationship between two or more classes.

Pet Store Examples


Entity: Customer, Merchandise, Sales
Class: Customer, Merchandise, Sale
Object: Joe Jones, Premium Cat Food, Sale #32
Property: LastName, Description, SaleDate
Method: AddCustomer, UpdateInventory, ComputeTotal
Association: Each Sale can have only one Customer.

8
Associations
• General • Objects related to objects
• One-to-one (1:1) • An employee can work in only
• One-to-many (1:M) one department
• Many-to-many (M:N) • Many departments can work
on many different products
• Relationships represent business
rules • Objects related to properties
• Sometimes common-sense • An employee can have only
places  one name
• Sometimes unique to an
organization • Many employees can have the
same last name
• Users often know current
relationships, rarely future
Breed 1 * Animal

Supplier1 *
Purch.
Cust. 1 * Sale Emp * * Tasks
Order
sent to places  performs 

9
Class Diagram .

• Class/Entity (box) Customer


• Association/Relationship 1…1
• Lines
• Minimum
• 0: optional
• 1: required 0…*
• Maximum
• Arrows Order
• 1, M 0…*

1…*

Item .

10
Sample Association Rules (Multiplicity)
Customer
• An order must have exactly 1 customer, 1…1
• 1…1 Minimum of 1
• 1…1 Maximum of 1
• And at least one item.
• 1…* Minimum of 1 0…*
• 1…* Maximum many Sale
• An item can show up on no orders or many orders. 0…*
• 0…* Optional (0)
• 0…* Maximum many

1…*

Item

11
N-ary Associations
• Associations can connect more than two classes. Employee
• Associations can become classes. *
• Events *
• Many-to-many * * Product
Component
• Need to keep data
• Example has two many-to-many relationships.
• We know which components go into each product.
• We know which employees worked on a product.
• We need to expand the relationships to show which
employees installed which components into each
product.
• Each assembly entry lists one employee, one component,
and one product.
• By appearing on many assembly rows, the many-to-many
relationships can still exist.

12
N-ary Association Example
EmployeeID Name …
Employee 11 Joe Jones …
Name 12 Maria Rio …
...
ProductID Type Name
* A3222 X32 Corvette
A5411 B17 Camaro

* *
Component Assembly Product
CompID ProductID
Type Type
Name Name
CompID Type Name
563 W32 Wheel Assembly EmployeeID CompId ProductID
872 M15 Mirror
882 H32 Door hinge
EmployeeID 11 563 A3222
883 H33 Trunk hinge CompID 11 872 A3222
888 T54 Trunk handle 11 563 A5411
ProductID 11 872 A5411
12 563 A3222
12 882 A3222
Multiplicity is defined as the number of items that 12 888 A3222
could appear if the other N-1 objects 12 883 A5411
are fixed. Almost always “many.”

13
Association Details: Aggregation
Sale Item

SaleDate * contains * Description


Employee Cost

Aggregation: the Sale consists of a set of Items being sold.

14
Association Details: Composition
Bicycle Wheels Bicycle
Size 1 built from 2 Rims
Size
Model Type Spokes
1 Model Type
… …
1 …

1 Crank Wheels

ItemID
Weight Crank

Two ways to 1 Stem


Stem
display ItemID
composition. Weight
Size

Composition: aggregation where the components become the new object.

15
Association Details: Generalization
Animal
DateBorn
Name
Gender
Color
ListPrice
{disjoint}

Mammal Fish Spider


LitterSize FreshWater Venomous
TailLength ScaleCondition Habitat
Claws

16
Inheritance Class name Accounts
AccountID
Properties CustomerID
• Class Definition--encapsulation DateOpened
• Class Name CurrentBalance
• Properties Methods OpenAccount
• Methods CloseAccount

• Inheritance Relationships
• Generic classes Inheritance
• Focus on differences Savings Accounts Checking Accounts
• Polymorphism InterestRate MinimumBalance
• Most existing DBMS do not handle inheritance Overdrafts

PayInterest BillOverdraftFees
CloseAccount

Polymorphism
17
Multiple Parents
Vehicle

Human
Motorized On-Road Off-Road
Powered

or

Car Bicycle

18
Association Details: Reflexive Relationship
manages

worker *

0…1
Employee manager

A reflexive relationship is an association from one class back to itself.


In this example, an employee can also be a manager of other employees.

19
Defining Packages for High-Level Views
Purchase Sell
Animals Animals

Supplier Employee Customer

Purchase Sell
Merchandise Merchandise

20
PetStore Overview Class Diagram
* *
Animal
1

* Animal *
Purchase

1 1 1
1 * * 1
Supplier Employee Sale Customer
1 1 *

Merchandise
* Purchase *

*
* Merchandise *

21
Pet Store Class Diagram: Access

22
Data Types (Domain)
• Common data types
• Text
• Fixed length 1 to 64 K bytes
• Variable length 1 to 2 G bytes
• Memo/Note
• Numeric
• Byte 1 byte 0 to 255
• Boolean 2 bytes True or False
• Integer 2 bytes -32,768 to 32,767 (no decimal points)
• Long 4 bytes -2,147,483,648 to 2,147,483,647 (no decimal
points)
• Floating 4 bytes 1.401298E-45 to 3.402823E38
• Double 8 bytes 4.94065645841247E-324 to
1.79769313486232E308
• Currency 8 bytes -922,377,203,685,477.5808 to
922,377,203,685,477.5807
• Date/Time 8 bytes Jan 1, 100 to Dec 31, 9999
• Objects/Raw binary
• Any type of data supported by the machine
• Pictures, sound, video . . .
23
Data Domain Comparison
Access SQL Server Oracle
Text
fixed char, nchar CHAR
variable Text varchar, nvarchar VARCHAR2,NVARCHAR2
memo Memo text, ntext LONG
Number
Byte (8 bits) Byte tinyint INTEGER
Integer (16 bits) Integer smallint INTEGER
Long (32 bits) Long int INTEGER
(64 bits) NA bigint NUMBER(127,0)
Fixed precision NA decimal(p,s) NUMBER(p,s)
Float Float real NUMBER, FLOAT
Double Double float NUMBER
Currency Currency money NUMBER(38,4)
Yes/No Yes/No bit INTEGER
Date/Time Date/Time datetime DATE
smalldatetime
Image OLE Object image LONG RAW, BLOB
AutoNumber AutoNumber Identity SEQUENCES
rowguidcol ROWID

24
Data Type Sizes
Size
Data Types Access SQL Server Oracle
Text (characters)
fixed 8 K, 4 K 2K
variable 255 8 K, 4 K 4K
memo 64 K 2 M, 1 M 2G
Numeric
Byte (8 bits) 255 255 38 digits
Integer (16 bits) +/- 32767 +/- 32767 38 digits
Long (32 bits) +/- 2 B +/- 2B 38 digits
(64 bits) NA 18 digits p: 38 digits
Fixed precision NA +/- 1 E 38 p: -84 to 127; s: 1 to 38
Float +/- 1 E 38 +/- 1 E 38 38 digits
Double +/- 1 E 308 +/- 1 E 308 38 digits
Currency +/- 900.0000 trillion +/- 900.0000 trillion 38 digits
Yes/No 0/1 0/1
Date/Time 1/1/100 – 12/31/9999 (1 sec) 1/1/1753 – 12/31/9999 (3 ms) 1/1/-4712, 1/31/9999 (sec)
1/1/1900 – 6/6/2079 (1 min)
Image OLE Object 2 GB 2 GB, 4 GB
AutoNumber Long (2 B) 2 B or 18 digits with bigint Column: 38 digit maximum

25
Computed Attributes
Denote computed values with a preceding slash (/).

Employee
Name
DateOfBirth
/Age {Age = Today - DateOfBirth}
Phone

26
Event Examples
• Business Event
• Item is sold.
• Decrease Inventory count.
• Data Event
• Inventory drops below preset level.
• Order more inventory.
• User Event
• User clicks on icon.
• Send purchase order to supplier.

Trigger

ON (QuantityOnHand < 100)


THEN Notify Purchasing Manager

27
Event Triggers
• Business Process: Ship  Object: Inventory
Product  Property: Current Inventory.
• Trigger: Inventory Change  Function: Update Inventory.
• Executes function/trigger in  Trigger: On Update, call
Inventory object. Analyze function.
 Process: Analyze Inventory
 Function: Determine need to
Order Inventory reorder.
… …  Trigger: Generate new order.
1. Subtract(Prod,
ShipOrder Subtract
Qty sold)
… Analyze
1.1 Analyze

low
… (Product)
1.1.1
Purchase Reorder
(Product,

quantity)
Reorder

28
Design Importance: Large Projects
• Design is harder on large projects.
• Communication with multiple users.
• Communication between IT workers.
• Need to divide project into pieces for teams.
• Finding data/components.
• Staff turnover--retraining.
• Need to monitor design process.
• Scheduling.
• Evaluation.
• Build systems that can be modified later.
• Documentation.
• Communication/underlying assumptions and model.

29
Large Projects
• Project Teams
planning software
• Divide
Schedules
the work
• Fit
Gantt
pieces
charts
together
• Evaluate
• CASE tools progress
•• Standards
Groupware tools
•• Design
Track changes
•• Templates
Document work
•• Actions
Track revisions
• Events
• Objects
• Naming convention
• Properties

30
CASE Tools
• Examples
Computer-Aided Software Engineering
• Rational Rose
Diagrams (linked)
• Data Dictionary
Sterling
• Teamwork
• COOL: Dat
• • COOL: Jex (UML)
Prototyping
• Oracle
• Forms
• IBM
• Reports
• Sample data
• Code generation
• Reverse Engineering

31
Rolling Thunder: Top-Level

Sales Bicycle Assembly

Employee

Location Purchasing

32
Rolling Thunder:
Customer
Sales 1…1 Bicycle::Bicycle
CustomerID
Phone BicycleID
1…1
FirstName 0…* …
LastName CustomerID
Address StoreID
0…* …
ZipCode
CityID
BalanceDue
Retail Store
Customer StoreID
Transaction StoreName 0…1
CustomerID Phone
TransactionDate ContactFirstName
0…*
EmployeeID ContactLastName
Amount Address
Description ZipCode
Reference CityID

33
Rolling Thunder: Bicycle
ModelType Bicycle 1…1 BicycleTubeUsed
1…1
ModelType SerialNumber 1…* SerialNumber
Description CustomerID 1…1
0…* ModelType TubeID
PaintID Quantity
Paint 0…* FrameSize
1…1 OrderDate
PaintID
StartDate
ColorName ShipDate
ColorStyle ShipEmployee
ColorList FrameAssembler
DateIntroduced Painter
BikeParts
0…*
DateDiscontinued Construction SerialNumber
WaterBottleBrazeOn ComponentID
CustomName SubstituteID
LetterStyleID Location
0…* StoreID
LetterStyle Quantity
1…1 EmployeeID
LetterStyleID TopTube
DateInstalled
Description ChainStay EmployeeID

34
Rolling Thunder: Assembly
Component
1…1
ComponentID
1…1
Bicycle::BikeParts GroupComponents
SerialNumber ManufacturerID 0…*
GroupID
ComponentID ProductNumber
0…* ComponentID
... Road
0…*
Category
Length 0…*
Height
Width Groupo
Description GroupID
ListPrice 1…1 GroupName
EstimatedCost BikeType
QuantityOnHand
ComponentName
Bicycle:: TubeMaterial 1…1
1…1 ComponentName
BicycleTubeUsed TubeID AssemblyOrder
SerialNumber Material Description
TubeID Description
0…* Diameter
Quantity

35
Rolling Thunder:
PurchaseOrder Purchasing
Manufacturer
1…1 1…1 1…1
PurchaseID ManufacturerID
EmployeeID ManufacturerName 1…1
ManufacturerID ContactName
TotalList 0…* Phone
ShippingCost Address
Discount ZipCode
OrderDate CityID
ReceiveDate BalanceDue
AmountDue
ManufacturerTrans
ManufacturerID 0…*
PurchaseItem TransactionDate
Reference Assembly::
PurchaseID 1…*
EmployeeID Component
ComponentID 1…1
0…* Amount ComponentID
PricePaid
Description ManufacturerID
Quantity
0…*
QuantityReceived ProductNumber

36
Rolling Thunder: Location
Sales:: Employee::
Customer City Employee
1…1 1…1
CustomerID CityID EmployeeID
… 0…* 1…1 ZipCode 1…1 …
CityID City CityID
State
1…1
AreaCode
Population1990
Sales:: Population1980
Country Purchasing::
RetailStore Manufacturer
Latitude
StoreID Longitude ManufacturerID
… 0…* …
CityID 0…*
CityID
StateTaxRate
0…1
State
TaxRate

37
Rolling Thunder: Employee
Employee
1…1 0…* worker
Bicycle:: EmployeeID
Bicycle 1…1 TaxpayerID 1…1
LastName Purchasing::
SerialNumber
… FirstName PurchaseOrder
0…* HomePhone PurchaseID
EmployeeID

manages
0…* Address …
ShipEmployee
0…* ZipCode
FrameAssembler EmployeeID
0…* 0…*
Painter CityID
DateHired
DateReleased
Bicycle:: CurrentManager 0…1
BikeParts SalaryGrade manager
SerialNumber Salary
ComponentID Title
… WorkArea
0…*
EmployeeID

38
Rolling Thunder: Combined

39
Application Design

• Simple form based on one table (Animal).


• But also need lookup tables for Category and Breed.

40

You might also like