Date post: | 26-Mar-2015 |
Category: |
Documents |
Upload: | jaden-schmitt |
View: | 223 times |
Download: | 0 times |
All Powder Board and Ski
Microsoft Access WorkbookChapter 3: Database TablesJerry PostCopyright © 2007
DBDesign: An Expert System
http://time-post.com/dbdesign Benefits
Makes it easy to create database diagrams Saves data in central location, so changes can be
made from almost any computer Provides immediate detailed feedback on the
design Requirements
Instructors must ask for a free account Instructors and students need a Java-enabled Web
browser
Identifying Key Columns
If you are uncertain about which columns to key. Write them down and evaluate the business rules.
OrderID CustomerID
For a given order, can there ever be more than one customer?If yes, then key CustomerID.In most businesses, only one customer per order, so do not key it.
For a given customer, can there ever be more than one order?If yes, then key OrderID, otherwise, do not key it.All businesses hope to get more than one order from a customer, so OrderID must be key. Underline it. Since OrderID is the only key,these columns belong in the Order table.
CustomerOrder(OrderID CustomerID, … )
AutoNumber
Customer Skill Level
CustomerID, LastName, … Style, SkillLevel
CustomerID, LastName, … Style, SkillLevel
Business rule: Each customer can have one skill in many styles.Business rule: Each style can apply to more than one customer.Need a table with both attributes as keys.
CustomerID, LastName, … Style, SkillLevel
But you cannot include LastName, FirstName and so on, because then you would have to re-enter that data for each customer skill.
Consider what happens if you (incorrectly) try to place Style and SkillLevel in the Customer table:
Customer Style Skills
Customer
CustomerIDLastNameFirstNamePhoneAddressCityStateZIP
CustomerSkill
CustomerIDStyleSkillLevel
Style
StyleStyleDescription
SkillLevel
SkillLevelSkillDescription
Action
ActionCreate Customer table in Design viewEnter column namesSelect data typesAssign the primary keySave the table
Creating Tables in Access
Primary key
Data type
Additional data type info
Column name
Data Types: Subtypes
Selected column
Number data type
Subtype: Single
Action
ActionSelect the Gender columnValidation rule: “Female” Or “Male” Or “Unidentified”Validation text: Please enter Female, Male, or Unidentified
Constraints
Selected column
Acceptable values
Message
Action
ActionSelect the Gender columnSelect the Lookup tabDisplay Control: Combo BoxRow Source Type: Value ListRow Source: “Female”;”Male”;”Unidentified”Switch to datasheet view and test it
Simple Lookup Lists
Selected column
Combo box
Value list
Values in quotes and separated by commas
Lookup tab
Database Table
Lookup listAutoNumber generated
Action
ActionTools/Relationships (or button)Add all tablesMove and resize them to fitDrag and drop key columns on foreign keysCheck integrity and cascade boxesDefine all relationships
Define Relationships
Relationship line
Check all three boxes
Add tables
Drag column and drop
Verify both columns
Create Tables with SQL
CREATE TABLE Customer (CustomerID Long,LastName Text(50),FirstName Text(50),Phone Text(50),Email Text(150),Address Text(50),State Text(50),ZIP Text(15),Gender Text(15),DateOfBirth Date,CONSTRAINT pk_Customer PRIMARY KEY (CustomerID)
)
Create Relationships with SQL
CREATE TABLE Rental (RentID Long,RentDate Date,CustomerID Long,ExpectedReturn Date,PaymentMethod Text(50)CONSTRAINT pk_Rental PRIMARY KEY (RentID)CONSTRAINT fk_RentalCustomer FOREIGN KEY (CustomerID)REFERENCES Customer(CustomerID)
)
ON DELETE CASCADEON UPDATE CASCADE
Note: ON DELETE AND ON UPDATE are not supported with Access 2002, but hopefully will be supported with 2003.
Estimating Database Size
CustomerID Long 4LastName Text(50) 30FirstName Text(50) 20Phone Text(50) 24Email Text(150) 50Address Text(50) 50State Text(50) 2ZIP Text(15) 14Gender Text(15) 10DateOfBirth Date 8
Average bytes per customer 212Customers per week (winter) *200Weeks (winter) *25Bytes added per year 1,060,000
Data Assumptions
200 customers per week for 25 weeks
2 skills per customer
2 rentals per customer per year
3 items per rental
20 percent of customers buy items
4 items per sale
100 manufacturers
20 models per manufacturer
5 items (sizes) per model
Action
ActionCreate a spreadsheetEnter table names as rowsAdd columns for: Bytes, Rows, TotalsCalculate the bytes per table rowEstimate the number of rowsCompute the table and overall totals
Database Table Sizes
Table Bytes Rows Comments TotalCustomer 212 5000 200 per week * 25 weeks 1,060,000CustomerSkill 68 10000 2 per customer 680,000Rental 44 10000 2 per customer 440,000RentItem 78 30000 3 items per rental 2,340,000PaymentMethod 20 5 basic methods 100Sale 152 1000 20 pct of customers buy 152,000SaleItem 36 4000 4 items per sale average 144,000Employee 248 35 Est. per year 8,680Department 70 5 basic list 350BindingStyle 120 15 main ones 1,800Manufacturer 262 100 should be enough 26,200ItemModel 174 2000 20 per manufacturer 348,000Inventory 48 10000 5 per model average 480,000ProductCategory 70 25 should be enough 1,750SkiBoardStyle 110 50 should be enough 5,500SkillLevel 74 10 10 main skill levels 740
5,689,120