Page 1
1 Copyright © 2010 Jerry Post. All rights reserved.
Database System Design
IS240 – DBMSLecture #3 – 2010-01-25
M. E. Kabay, PhD, CISSP-ISSMPAssoc. Prof. Information Assurance
School of Business & Management, Norwich University mailto:[email protected] V: 802.479.7937
Page 2
2 Copyright © 2010 Jerry Post. All rights reserved.
Topics
OverviewDesignEntities / ClassesUMLAssociations InheritancePetStoreData TypesEventsRolling Thunder
Page 3
3 Copyright © 2010 Jerry Post. All rights reserved.
Overview
User viewsof data.
Conceptualdata model.
Customer(CustomerID, Name, Address, …)
SalesPerson(EmployeeID, Name, Commission, … )
Order(OrderID, OrderDate, CustomerID, EmployeeID, … )
OrderItem(OrderID, ItemID, Quantity, Price, … )
Item(ItemID, Description, ListPrice, …)
Implementation(relational)data model.
Physicaldatastorage.
Class diagram that shows business entities,
relationships, and rules.
List of nicely-behaved
tables. Use data normaliza-tion to derive
list.
Indexes and storage
methods to improve
performance.
Page 4
4 Copyright © 2010 Jerry Post. All rights reserved.
The Need for Design
Goal: To produce an information system that adds value for userReduce costsIncrease sales/revenueProvide competitive advantage
Objective: To understand systemTo improve itTo communicate with users and IT staff
Methodology: Build models of system
Page 5
5 Copyright © 2010 Jerry Post. All rights reserved.
Designing SystemsDesigns model existing & proposed systems
Provide picture or representation of realitySimplificationSomeone should be able to read your design
(model) and describe features of actual system.You build models by talking with users
Identify processesIdentify objectsDetermine current problems and future needsCollect user documents (views)
Break complex systems into pieces and levels
Page 6
6 Copyright © 2010 Jerry Post. All rights reserved.
Design Stages Initiation
ScopeFeasibilityCost & Time estimates
Requirements AnalysisUser Views & Needs
FormsReports
Processes & EventsObjects & Attributes
Conceptual DesignModels
Data flow diagramEntity
RelationshipsObjects
User feedback
Physical DesignTable definitionsApplication development
QueriesFormsReportsApplication
integrationData storageSecurityProcedures
ImplementationTrainingPurchasesData conversion Installation
Evaluation & Review
Page 7
7 Copyright © 2010 Jerry Post. All rights reserved.
Initial Steps of Design
1. Identify exact goals of system.
2. Talk with users to identify basic forms and reports.
3. Identify data items to be stored.
4. Design classes (tables) and relationships.
5. Identify any business constraints.
6. Verify design matches business rules.
Page 8
8 Copyright © 2010 Jerry Post. All rights reserved.
Entities/ClassesCustomer
CustomerIDLastNameFirstNamePhoneAddressCityStateZIP Code
Name
Properties
Add Customer
Delete Customer
Methods
(optional for database)
Page 9
9 Copyright © 2010 Jerry Post. All rights reserved.
Definitions Relational database: A collection of tables. Table: collection of columns (attributes) describing an entity.
Individual objects stored as rows of data in table. Property (attribute): characteristic or descriptor of class or
entity. Every table has primary key.
The smallest set of columns that uniquely identifies any rowPrimary keys can span more than one column (concatenated
keys)We often create primary key to insure uniqueness (e.g.,
CustomerID, Product#, . . .) called surrogate key.
EmployeeID TaxpayerID LastName FirstName HomePhone Address12512 888-22-5552 Cartom Abdul (603) 323-9893 252 South Street15293 222-55-3737 Venetiaan Roland (804) 888-6667 937 Paramaribo Lane22343 293-87-4343 Johnson John (703) 222-9384 234 Main Street29387 837-36-2933 Stenheim Susan (410) 330-9837 8934 W. Maple
Employee
Properties
Rows/ObjectsClass: Employee
Primary key
Page 10
11 Copyright © 2010 Jerry Post. All rights reserved.
DefinitionsEntity: Something in 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 class with specific data.Property: A characteristic or descriptor of class or entity.Method: A function that is performed by class.Association: A relationship between two or more
classes.
Entity: Customer, Merchandise, SalesClass: Customer, Merchandise, SaleObject: Joe Jones, Premium Cat Food, Sale #32Property: LastName, Description, SaleDateMethod: AddCustomer, UpdateInventory, ComputeTotalAssociation: Each Sale can have only one Customer.
Pet Store Examples
Page 11
12 Copyright © 2010 Jerry Post. All rights reserved.
Associations General
One-to-one (1:1)One-to-many (1:M)Many-to-many (M:N)
Relationships represent business rules
Sometimes common-sense
Sometimes unique to an organization
Users often know current relationships, rarely future
Objects related to objectsAn employee can work
in only one departmentMany departments can
work on many different products
Objects related to properties
An employee can have only one name
Many employees can have same last name
1 * AnimalBreed
* *performs
TasksEmp1 *places
SaleCust.1 * Purch.Order
Supplier
sent to
Page 12
13 Copyright © 2010 Jerry Post. All rights reserved.
Class Diagram
Class/Entity (box) Association/Relationship
Lines Minimum
0: optional1: required
MaximumArrows1, M
Customer
Order
Item
1 … 1
0 … *
0 … *
1 … *
Page 13
14 Copyright © 2010 Jerry Post. All rights reserved.
Sample Association Rules (Multiplicity)
An order must have exactly 1 customer,
1 … 1 Minimum of 1 1 … 1 Maximum of 1
And at least one item. 1 … * Minimum of 1 1 … * Maximum many
An item can show up on no orders or many orders.
0 … * Optional (0) 0 … * Maximum many
Customer
Order
Item
1 … 1
0 … *
0 … *
1 … *
Page 14
15 Copyright © 2010 Jerry Post. All rights reserved.
N-ary Associations Associations can connect more than two classes. Associations can become classes.
EventsMany-to-manyNeed to keep data
Example has two many-to-many relationships.We know which components go into each
product.We know which employees worked on product.
We need to expand 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, many-to-
many relationships can still exist.
Employee
Component Product
**
* *
Page 15
16 Copyright © 2010 Jerry Post. All rights reserved.
N-ary Association ExampleEmployeeName...
ComponentCompIDTypeName
ProductProductIDTypeName
EmployeeID Name …11 J oe J ones …12 Maria Rio …
ProductID Type NameA3222 X32 CorvetteA5411 B17 Camaro
EmployeeID CompId ProductID11 563 A322211 872 A322211 563 A541111 872 A541112 563 A322212 882 A322212 888 A322212 883 A5411
CompID Type Name563 W32 Wheel872 M15 Mirror882 H32 Door hinge883 H33 Trunk hinge888 T54 Trunk handle
*
* *Assembly
AssemblyEmployeeIDCompIDProductID
Multiplicity is defined as number of items that could appear if other N-1 objectsare fixed. Almost always “many.”
1
1
1
Page 16
17 Copyright © 2010 Jerry Post. All rights reserved.
Association Details: Aggregation
Sale
SaleDateEmployee
Item
DescriptionCost
* *contains
Aggregation: Sale consists of set of Items being sold.
Page 17
18 Copyright © 2010 Jerry Post. All rights reserved.
Association Details: Composition
Bicycle
SizeModel Type…
Wheels
RimsSpokes…
1 2built from
Composition: aggregation where components become new object.
Crank
ItemIDWeight
Stem
ItemIDWeightSize
1
1
1
1
Bicycle
SizeModel Type…
Wheels
Crank
StemTwo ways to display composition.
Page 18
19 Copyright © 2010 Jerry Post. All rights reserved.
Association Details: Generalization
AnimalDateBornNameGenderColorListPrice
MammalLitterSizeTailLengthClaws
FishFreshWaterScaleCondition
SpiderVenomousHabitat
{disjoint}
Page 19
20 Copyright © 2010 Jerry Post. All rights reserved.
Inheritance Class Definition—
encapsulationClass NamePropertiesMethods
Inheritance RelationshipsGeneric classesFocus on differencesPolymorphismMost existing DBMS
do not handle inheritance
Accounts
AccountIDCustomerIDDateOpenedCurrentBalanceOpenAccountCloseAccount
Class name
Properties
Methods
Savings Accounts
InterestRate
PayInterest
Checking Accounts
MinimumBalanceOverdrafts
BillOverdraftFeesCloseAccount
Inheritance
Polymorphism
Page 20
21 Copyright © 2010 Jerry Post. All rights reserved.
Multiple Parents
Vehicle
Human Powered
Motorized On-Road Off-Road
Car Bicycle
or
Page 21
22 Copyright © 2010 Jerry Post. All rights reserved.
Association Details: Reflexive Relationship
Employee manager0…1
worker *
manages
A reflexive relationship is an association from one class back to itself.
In this example, an employee can also be manager of other employees.
Page 22
24 Copyright © 2010 Jerry Post. All rights reserved.
PetStore Overview Class Diagram
Animal
CustomerSupplier
Merchandise
AnimalPurchase
MerchandisePurchase
SaleEmployee
*
1
*
1
1
* *
1
1
**
1
*
*
*
*
* 1*1
Page 23
25 Copyright © 2010 Jerry Post. All rights reserved.
Pet Store Class Diagram: Access
Page 24
27 Copyright © 2010 Jerry Post. All rights reserved.
Data Types (cont’d)
NumericByte 1 byte 0 to 255Boolean 2 bytes True or FalseInteger 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.402823E38Double 8 bytes 4.94065645841247E-324 to
1.79769313486232E308Currency 8 bytes -922,377,203,685,477.5808 to
922,377,203,685,477.5807
Page 25
28 Copyright © 2010 Jerry Post. All rights reserved.
Data Type SizesAccess SQL Server Oracle
Text fixed variable Unicode memo
TextMemo
char,varcharnchar, nvarchartext
CHARVARCHAR2NVARCHAR2LONG
Number Byte (8 bits) Integer (16 bits) Long (32 bits) (64 bits) Fixed precision Float Double Currency Yes/No
ByteIntegerLongNANAFloatDoubleCurrencyYes/No
tinyintsmallintintbigintdecimal(p,s)realfloatmoneybit
INTEGERINTEGERINTEGERNUMBER(38,0)NUMBER(p,s)NUMBER, FLOATNUMBERNUMBER(38,4)INTEGER
Date/TimeInterval
Date/TimeNA
datetimesmalldatetimeinterval year …
DATEINTERVAL YEAR …
Image OLE Object image LONG RAW, BLOB
AutoNumber AutoNumber Identityrowguidcol
SEQUENCESROWID
Page 26
29 Copyright © 2010 Jerry Post. All rights reserved.
Computed AttributesDenote computed values with preceding slash (/).
EmployeeNameDateOfBirth/AgePhone…
{Age = Today - DateOfBirth}
Page 27
30 Copyright © 2010 Jerry Post. All rights reserved.
Event Examples Business Event
Item is sold.Decrease Inventory count.
Data Event Inventory drops below preset level.Order more inventory.
User EventUser clicks on icon.Send purchase order to supplier.
ON (QuantityOnHand < 100)
THEN Notify Purchasing Manager
Trigger
Page 28
31 Copyright © 2010 Jerry Post. All rights reserved.
Event Triggers Business Process: Ship
ProductTrigger: Inventory
ChangeExecutes
function/trigger in Inventory object.
Order… ShipOrder…
Inventory… SubtractAnalyze…
1. Subtract(Prod, Qty sold)
1.1 Analyze(Product)
Purchase… Reorder…
1.1.1Reorder(Product, quantity)
low
Inventory… SubtractAnalyze…
Object: InventoryProperty: Current
Inventory.Function: Update
Inventory.Trigger: On Update, call
Analyze function. Process: Analyze Inventory
Function: Determine need to reorder.
Trigger: Generate new order.
Page 29
32 Copyright © 2010 Jerry Post. All rights reserved.
Design Importance: Large ProjectsDesign 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.
Page 30
33 Copyright © 2010 Jerry Post. All rights reserved.
Large Projects Project planning
softwareSchedulesGantt charts
CASE tools Groupware tools
Track changesDocument workTrack revisions
Project TeamsDivide workFit pieces togetherEvaluate progress
StandardsDesignTemplatesActionsEventsObjects
Naming convention
Properties
Page 31
34 Copyright © 2010 Jerry Post. All rights reserved.
CASE Tools
Computer-Aided Software Engineering
Diagrams (linked)Data DictionaryTeamworkPrototyping
FormsReportsSample data
Code generationReverse Engineering
ExamplesRational RoseSterling
COOL: DatCOOL: Jex
(UML)Oracle IBM
Page 32
35 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Top-Level
Sales Assembly
PurchasingLocation
Bicycle
Employee
Page 33
36 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Sales
Customer
CustomerIDPhoneFirstNameLastNameAddressZipCodeCityIDBalanceDue
CustomerTransaction
CustomerIDTransactionDateEmployeeIDAmountDescriptionReference
Retail Store
StoreIDStoreNamePhoneContactFirstNameContactLastNameAddressZipCodeCityID
Bicycle::Bicycle
BicycleID… CustomerIDStoreID…
1…1
0…*1…1
0…*
0…*
0…1
Page 34
37 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Bicycle
BicycleSerialNumberCustomerIDModelTypePaintIDFrameSizeOrderDateStartDateShipDateShipEmployeeFrameAssemblerPainterConstructionWaterBottleBrazeOnCustomNameLetterStyleIDStoreIDEmployeeIDTopTubeChainStay…
1…1ModelTypeModelTypeDescription
PaintPaintIDColorNameColorStyleColorListDateIntroducedDateDiscontinued
LetterStyleLetterStyleIDDescription
BicycleTubeUsedSerialNumberTubeIDQuantity
BikePartsSerialNumberComponentIDSubstituteIDLocationQuantityDateInstalledEmployeeID
1…*
0…*
1…1
1…1
0…*
0…*
0…*
1…1
1…1
Page 35
38 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Assembly
Bicycle::BikePartsSerialNumberComponentID...
1…1
ComponentComponentIDManufacturerIDProductNumberRoadCategoryLengthHeightWidthDescriptionListPriceEstimatedCostQuantityOnHand
ComponentNameComponentNameAssemblyOrderDescription
GroupComponentsGroupIDComponentID
GroupoGroupIDGroupNameBikeType
Bicycle::BicycleTubeUsedSerialNumberTubeIDQuantity
TubeMaterialTubeIDMaterialDescriptionDiameter…
0…*
1…1
0…*
1…1
0…*
1…1
0…*
0…*
1…1
Page 36
39 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Purchasing
PurchaseOrderPurchaseIDEmployeeIDManufacturerIDTotalListShippingCostDiscountOrderDateReceiveDateAmountDue
1…1
PurchaseItemPurchaseIDComponentIDPricePaidQuantityQuantityReceived
ManufacturerManufacturerIDManufacturerNameContactNamePhoneAddressZipCodeCityIDBalanceDue
ManufacturerTransManufacturerIDTransactionDateReferenceEmployeeIDAmountDescription
Assembly::Component
ComponentIDManufacturerIDProductNumber
0…*
1…1
1…1
1…1
0…*
1…1
1…*
0…*
0…*
Page 37
40 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Location
CityCityIDZipCodeCityStateAreaCodePopulation1990Population1980CountryLatitudeLongitude
Sales::Customer
CustomerID…CityID
Sales::RetailStore
StoreID…CityID
Employee::Employee
EmployeeID…CityID
Purchasing::Manufacturer
ManufacturerID…CityID
0…*
1…1
1…1
1…1
1…1
0…*0…*
StateTaxRateStateTaxRate
1…1
0…1
Page 38
41 Copyright © 2010 Jerry Post. All rights reserved.
Rolling Thunder: Employee
EmployeeEmployeeIDTaxpayerIDLastNameFirstNameHomePhoneAddressZipCodeCityIDDateHiredDateReleasedCurrentManagerSalaryGradeSalaryTitleWorkArea
Bicycle::Bicycle
SerialNumber…EmployeeIDShipEmployeeFrameAssemblerPainter
Bicycle::BikeParts
SerialNumberComponentID…EmployeeID
Purchasing::PurchaseOrderPurchaseID…EmployeeID
1…1
0…*0…*0…*0…*
0…*
1…1 1…1
0…*
manager
man
ages
worker0…*
0…1
Page 39
42 Copyright © 2010 Jerry Post. All rights reserved.
CustomerIDPhoneFirstNameLastNameAddressZipCodeCityIDBalanceDue
Customer
CustomerIDTransDateEmployeeIDAmountDescriptionReference
CustomerTrans
StoreIDStoreNamePhoneContacFirstNameContactLastNameAddressZipcodeCityID
RetailStore
StateTaxRate
StateTaxRate
SerialNumberCustomerIDModelTypePaintIDFrameSizeOrderDateStartDateShipDateShipEmployeeFrameAssemblerPainterConstructionWaterBottleCustomNameLetterStyleIDStoreIDEmployeeIDTopTubeChainStayHeadTubeAngleSeatTueAngleListPriceSalePriceSalesTaxSaleStateShipPriceFramePriceComponentList
Bicycle
CityIDZipCodeCityStateAreaCodePopulation1990Population1980CountryLatitudeLongitude
Customer
ModelTypeDescriptionComponentID
ModelType
Paint
EmployeeIDTaxpayerIDLastNameFirstNameHomePhoneAddressZipCodeCityIDDateHiredDateReleasedCurrentManagerSalaryGradeSalaryTitleWorkArea
Employee
SerialNumberTubeIDQuantity
BicycleTube
ModelTypeMSizeTopTubeChainStayTotalLengthGroundClearanceHeadTubeAngleSeatTubeAngle
ModelSize
LetterStyleDescription
LetterStyle
PurchaseIDEmployeeIDManufacturerIDTotalListShippingCostDiscountOrderDateReceiveDateAmountDue
PurchaseOrder
SerialNumberTubeNameTubeIDLength
BikeTubes
SerialNumberComponentIDSubstituteIDLocationQuantityDateInstalledEmployeeID
BikeParts
PurchaseIDComponentIDPricePaidQuantityQuantityReceived
PurchaseItem
ManufacturerIDManufacturerNameContactNamePhoneAddressZipCodeCityIDBalanceDue
Manufacturer
CompGroupGroupNameBikeTypeYearEndYearWeight
Groupo
ComponentIDManufacturerIDProductNumberRoadCategoryLengthHeightWidthWeightYearEndYearDescriptionListPriceEstimatedCostQuantityOnHand
Component
ManufacturerIDTransactionDateEmployeeIDAmountDescriptionReference
ManufacturerTrans
TubeIDMaterialDescriptionDiameterThicknessRoundnessWeightStiffnessListPriceConstruction
TubeMaterial
GroupIDComponentID
GroupCompon
ComponentNameAssemblyOrderDescription
ComponentName
PaintIDColorNameColorStyleColorListDateIntroducedDateDiscontinued
Rolling Thunder Combined
Page 40
44 Copyright © 2010 Jerry Post. All rights reserved.
Application Design
Simple form based on one table (Animal). But also need lookup tables for Category and Breed.
Page 41
45 Copyright © 2010 Jerry Post. All rights reserved.
REQUIRED HOMEWORK (1)By Sunday 7 Feb 2010 at 23:59Read all of Chapter 2 in the textComplete Review Questions 1-10 yourself for practiceFor exercises using Dr Post’s computer-based
traininghttp://www.jerrypost.com/DBDesignYour AdmitCode is ____________ (write it in; all
UC)Design the database tables required to support the
situations described in the following problems in Chapter 2 USING THE DBDesign System onlineComplete problems 1 & 3 online (10 points each)
Answer question 9 (18 pts) in writing and explain your reasoning for every answer by articulating assumptions. Provide minimum and maximum values
Page 42
46 Copyright © 2010 Jerry Post. All rights reserved.
REQUIRED HOMEWORK (2)Answer question 10 (15 pts) by indicating A
or E for attributes or entities as described in the question.
For 10 points each, COMPLETE one of these sets:11-14 (Sally’s Pet Store)15-17 (Rolling Thunder Bicycles)18-20 (Corner Med)(Complete one or two other sets for a up to
20 extra pts)
Page 43
47 Copyright © 2010 Jerry Post. All rights reserved.
DISCUSSION