spine=1.10"
Wrox Programmer to Programmer TM
Beginning
Wrox Programmer to Programmer TM
Stephens
Database Design Solutions
Databases play a critical role in the business operations of most organizations;
they’re the central repository for critical information on products, customers,
suppliers, sales, and a host of other essential information. It’s no wonder that
the majority of all business computing involves database applications.
Beginning
This book provides readers with proven methods and tools for designing efficient,
reliable, and secure databases. Author Rod Stephens explains how a database
should be organized to ensure data integrity without sacrificing performance.
He shares procedures for designing robust, flexible, and secure databases that
provide a solid foundation for all of your database applications. The methods
and techniques in this book can be applied to any database environment,
including Oracle®, Microsoft Access®, SQL Server®, and MySQL®. You’ll learn
the basics of good database design and ultimately discover how to design a
real-world database.
What you will learn from this book
● How to identify database requirements that meet users’ needs
● Ways to build data models using a variety of modeling techniques, including
entity-relational models, user-interface models, and semantic object models
● Tips for understanding the different types of databases, including relational
Enhance Your Knowledge
databases, flat files, spreadsheets, XML and object databases
Advance Your Career
● How to refine and tune the design to improve database performance
● Techniques for understanding the relationship between good application design and database design
● Methods for designing flexible and robust databases that can adapt to business change and growth
● Ways to design for ease of maintenance and support
● How to avoid common database design mistakes
Who this book is for
This book is for anyone interested in learning to design, build, analyze, and understand databases. No previous experience with
databases or programs is required.
Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing
a structured, tutorial format that will guide you through all the techniques involved.
Database Design
Solutions
With so much at stake, you’d expect most IT professionals would have a firm
understanding of good database design. But in fact most learn through a painful
process of trial and error, with predictably poor results.
Beginning
Database Design
Solutions
subtitle
www.wrox.com
Recommended
Computer Book
Categories
$44.99 USA
$48.99 CAN
Database Management
General
ISBN: 978-0-470-38549-4
Rod Stephens
Updates, source code, and Wrox technical support at www.wrox.com
www.it-ebooks.info
spine=1.10"
Programmer to Programmer™
Get more out of
WROX.com
Beginning
Database Design Solutions
Professional Microsoft SQL Server 2008 Integration
Services
978-0-470-24795-2
This book shows developers how to master the 2008 release of SSIS,
covering topics including data warehousing with SSIS, new methods of
managing the SSIS platform, and improved techniques for ETL operations.
Professional SQL Server 2008 Reporting Services
978-0-470-24201-8
This book teaches solutions architects, designers, and developers how
to use Microsoft’s reporting platform to create reporting and business
intelligence solutions.
Professional Microsoft SQL Server 2008 Analysis Services
Interact
Chapters on Demand
Take an active role online by participating in
our P2P forums
Purchase individual book chapters in pdf
format
Wrox Online Library
Join the Community
Hundreds of our books are available online
through Books24x7.com
Sign up for our free monthly newsletter at
newsletter.wrox.com
Wrox Blox
Browse
Download short informational pieces and
code to keep you up to date and out of
trouble!
Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!
978-0-470-24798-3
Professional Microsoft SQL Server 2008 Analysis Services shows readers
how to build data warehouses and multidimensional databases, query
databases, and use Analysis Services and other components of SQL Server
to provide end-to-end solutions.
Professional Microsoft SQL Server 2008 Programming
Enhance Your Knowledge
Advance Your Career
978-0-470-25702-9
This updated new edition of Wrox’s best-selling SQL Server book has been
expanded to include coverage of SQL Server 2008’s new datatypes, new
indexing structures, manageability features, and advanced time-zone
handling.
Professional Microsoft SQL Server 2008 Administration
978-0-470-24796-9
A how-to guide for experienced database administrators, this book is loaded
with unique tips, tricks, and workarounds for handling the most difficult SQL Server administration issues. The authors discuss
data capture, performance studio, Query Governor, and new techniques for monitoring and policy management.
Beginning Microsoft SQL Server 2008 Programming
978-0-470-25701-2
This comprehensive introduction to SQL Server covers the fundamentals and moves on to discuss how to create and change
tables, manage keys, write scripts, work with stored procedures, and much more.
Beginning T-SQL with Microsoft SQL Server 2005 and 2008
978-0-470-25703-6
Beginning T-SQL with Microsoft SQL Server 2005 and 2008 provides a comprehensive introduction to the T-SQL programming
language, with concrete examples showing how T-SQL works with both SQL Server 2005 and SQL Server 2008.
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing
Beginning Database Design Solutions
978-0-470-38549-4
Beginning Database Design Solutions introduces IT professionals—both DBAs and database developers—to database design.
It explains what databases are, their goals, and why proper design is necessary to achieve those goals. It tells how to decide
what should be in a database to meet the application’s requirements. It tells how to structure the database so it gives good
performance while minimizing the chance for error.
www.it-ebooks.info
Stephens
ffirs.tex V3 - 10/03/2008
4:09am
Beginning
Database Design Solutions
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Part I: Introduction to Databases and Database Design
1
Chapter 1: Goals of Effective Database Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Database Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Chapter 3: Relational Database Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Part II: Database Design Process and Techniques
63
Chapter 4: Understanding User Needs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Chapter 5: Translating User Needs into Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Chapter 6: Extracting Business Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Chapter 7: Normalizing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Chapter 8: Designing Databases to Support Software Applications . . . . . . . . . . . . . . . . . . . . . 173
Chapter 9: Common Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Chapter 10: Common Design Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Part III: A Detailed Case Study
Chapter 11: User Needs and Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 12: Building a Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 13: Extracting Business Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 14: Normalization and Refinement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part IV: Implementing Databases (with Examples in Access
and MySQL)
225
227
245
263
273
285
Chapter 15: Microsoft Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Chapter 16: MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Part V: Advanced Topics
Chapter 17: Introduction to SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 18: Building Databases with SQL Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 19: Database Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 20: Database Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix A: Exercise Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix B: Sample Database Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
www.it-ebooks.info
343
345
369
379
389
403
467
487
497
Page i
Stephens ffirs.tex V3 - 10/03/2008
www.it-ebooks.info
4:09am
Page ii
Stephens ffirs.tex V3 - 10/03/2008
Beginning
Database Design Solutions
www.it-ebooks.info
4:09am
Page iii
Stephens
www.it-ebooks.info
ffirs.tex V3 - 10/03/2008
4:09am
Page iv
Stephens
ffirs.tex V3 - 10/03/2008
Beginning
Database Design Solutions
Rod Stephens
Wiley Publishing, Inc.
www.it-ebooks.info
4:09am
Page v
Stephens
ffirs.tex V3 - 10/03/2008
Beginning Database Design Solutions
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-38549-4
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data
Stephens, Rod, 1961Beginning database design solutions / Rod Stephens.
p. cm.
Includes index.
ISBN 978-0-470-38549-4 (978-0-470-38549-4)
1. Database design. 2. Databases. I. Title.
QA76.9.D26S97 2008
005.74 — dc22
2008037282
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, or online at />Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties
with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties,
including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended
by sales or promotional materials. The advice and strategies contained herein may not be suitable for every
situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting,
or other professional services. If professional assistance is required, the services of a competent professional person
should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an
organization or Web site is referred to in this work as a citation and/or a potential source of further information
does not mean that the author or the publisher endorses the information the organization or Web site may provide
or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may
have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and
other countries, and may not be used without written permission. All other trademarks are the property of their
respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic books.
www.it-ebooks.info
4:09am
Page vi
Stephens f01.tex
V3 - 10/01/2008
3:23am
About the Author
Rod Stephens started out as a mathematician but, while studying at MIT, discovered the joys of computer
algorithms and programming and he’s been programming professionally ever since. During his career,
he has worked on a wide variety of applications in such diverse fields as telephone switching, billing,
repair dispatching, tax processing, wastewater treatment, concert ticket sales, cartography, and training
for professional football players.
Rod is a Microsoft Visual Basic Most Valuable Professional (MVP), consultant and author. He has written
18 books that have been translated into half a dozen different languages, and more than 250 magazine
articles, mostly about Visual Basic. Currently he is a regular contributor of C# and Visual Basic articles at
DevX.com (www.devx.com).
Rod’s popular VB Helper Web site www.vb-helper.com receives several million hits per month and contains thousands of pages of tips, tricks, and example code for Visual Basic programmers, as well as
example code for this book.
www.it-ebooks.info
Page vii
Stephens
www.it-ebooks.info
f01.tex
V3 - 10/01/2008
3:23am
Page viii
Stephens f02.tex
V3 - 10/01/2008
3:23am
Credits
Executive Editor
Robert Elliott
Production Manager
Tim Tate
Development Editor
Sydney Jones
Vice President and Executive Group Publisher
Richard Swadley
Technical Editor
Steve Hoberman
Vice President and Executive Publisher
Joseph B. Wikert
Production Editor
Angela Smith
Project Coordinator, Cover
Lynsey Stanford
Copy Editor
Kim Cofer
Proofreader
Publication Services, Inc.
Editorial Manager
Mary Beth Wakefield
Indexer
Jack Lewis
www.it-ebooks.info
Page ix
Stephens f02.tex
www.it-ebooks.info
V3 - 10/01/2008
3:23am
Page x
Stephens f03.tex
V3 - 10/01/2008
3:25am
Acknowledgments
Thanks to Bob Elliott, Sydney Jones, Steve Hoberman, and all of the others whose hard work went into
producing this book.
Special thanks to Sydney Jones for putting up with my sometimes overly generous interpretation of the
Wrox guidelines.
www.it-ebooks.info
Page xi
Stephens f03.tex
www.it-ebooks.info
V3 - 10/01/2008
3:25am
Page xii
Stephens ftoc.tex V2 - 10/03/2008
4:13am
Contents
Introduction
Part I:
xxiii
Introduction to Databases and Database Design
Chapter 1: Goals of Effective Database Design
Understanding the Importance of Design
Information Containers
Strengths and Weaknesses of Information Containers
Desirable Database Features
CRUD
Retrieval
Consistency
Validity
Easy Error Correction
Speed
Atomic Transactions
ACID
Persistence and Backups
Low Cost and Extensibility
Ease of Use
Portability
Security
Sharing
Ability to Perform Complex Calculations
Consequences of Good and Bad Design
Summary
Exercises
3
4
5
7
8
9
9
10
10
11
11
12
13
14
16
16
16
17
18
19
19
21
22
Chapter 2: Database Types
23
Why Bother?
Flat Files
24
24
INI Files
Windows System Registry
26
26
Relational Databases
27
www.it-ebooks.info
Page xiii
Stephens
ftoc.tex V2 - 10/03/2008
Contents
Spreadsheets
Hierarchical Databases
XML
30
31
34
XML Basics
XML Structures
XML Summary
34
37
39
Network
Object
Object-Relational
Exotic
40
42
43
44
Document-Oriented
Deductive
Dimensional
Temporal
44
44
44
45
Summary
Exercises
45
47
Chapter 3: Relational Database Fundamentals
Relational Points of View
Table, Rows, and Columns
Relations, Attributes, and Tuples
Keys
Indexes
Constraints
49
50
52
52
54
55
Basic Constraints
Check Constraints
Primary Key Constraints
Unique Constraints
Foreign Key Constraints
55
55
55
56
56
Database Operations
Summary
Exercises
Part II:
49
57
59
59
Database Design Process and Techniques
Chapter 4: Understanding User Needs
Make a Plan
Bring a List of Questions
65
66
67
Functionality
Data Needs
Data Integrity
67
67
68
xiv
www.it-ebooks.info
4:13am
Page xiv
Stephens ftoc.tex V2 - 10/03/2008
4:13am
Contents
Security
Environment
68
69
Meet the Customers
Learn Who’s Who
Pick the Customers’ Brains
Walk a Mile in the User’s Shoes
Study Current Operations
Brainstorm
Look to the Future
Understand the Customers’ Reasoning
Learn What the Customers Really Need
Prioritize
Verify Your Understanding
Write the Requirements Document
Make Use Cases
Decide Feasibility
Summary
Exercises
Chapter 5: Translating User Needs into Data Models
69
70
73
73
74
75
76
76
77
78
79
80
81
85
85
86
89
What Are Data Models?
User Interface Models
Semantic Object Models
90
92
96
Classes and Objects
Cardinality
Identifiers
Putting It Together
Semantic Views
Class Types
Comments and Notes
96
97
97
97
99
100
106
Entity-Relationship Models
106
Entities, Attributes, and Identifiers
Relationships
Cardinality
Inheritance
Additional Conventions
Comments and Notes
Relational Models
107
107
108
109
112
113
113
Converting Semantic Object Models
Converting ER Diagrams
Summary
Exercises
113
116
117
118
xv
www.it-ebooks.info
Page xv
Stephens
ftoc.tex V2 - 10/03/2008
Contents
Chapter 6: Extracting Business Rules
What Are Business Rules?
Identifying Key Business Rules
Extracting Key Business Rules
Multi-Tier Applications
Summary
Exercises
121
121
123
128
129
133
134
Chapter 7: Normalizing Data
137
What Is Normalization?
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Stopping at Third Normal Form
Boyce-Codd Normal Form (BCNF)
Fourth Normal Form (4NF)
Fifth Normal Form (5NF)
Domain/Key Normal Form (DKNF)
Essential Redundancy
The Best Level of Normalization
Summary
Exercises
137
138
146
150
154
154
158
162
165
167
168
169
170
Chapter 8: Designing Databases to Support Software Applications
Plan Ahead
Document Everything
Consider Multi-Tier Architecture
Convert Domains into Tables
Keep Tables Focused
Use Three Kinds of Tables
Use Naming Conventions
Allow Some Redundant Data
Don’t Squeeze in Everything
Summary
Exercises
173
173
174
175
175
176
176
178
179
180
181
182
Chapter 9: Common Design Patterns
Associations
185
185
Many-to-Many Associations
Multiple Many-to-Many Associations
186
186
xvi
www.it-ebooks.info
4:13am
Page xvi
Stephens
ftoc.tex V2 - 10/03/2008
4:13am
Contents
Multiple-Object Associations
Repeated Attribute Associations
Reflexive Associations
Temporal Data
188
191
193
200
Effective Dates
Deleted Objects
Deciding What to Temporalize
200
202
203
Logging and Locking
203
Audit Trails
Turnkey Records
203
204
Summary
Exercises
205
205
Chapter 10: Common Design Pitfalls
Lack of Preparation
Poor Documentation
Poor Naming Standards
Thinking Too Small
Not Planning for Change
Too Much Normalization
Insufficient Normalization
Insufficient Testing
Performance Anxiety
Mishmash Tables
Not Enforcing Constraints
Obsession with IDs
Not Defining Natural Keys
Summary
Exercises
Part III:
207
207
208
208
210
210
213
213
214
214
215
217
218
220
221
222
A Detailed Case Study
Chapter 11: User Needs and Requirements
Meet the Customers
Pick the Customers’ Brains
227
227
229
Determining What the System Should Do
Determining How the Project Should Look
Determining What Data Is Needed for the User Interface
Determining Where the Data Should Come From
Determining How the Pieces of Data Are Related
Determining Performance Needs
229
231
232
233
233
235
xvii
www.it-ebooks.info
Page xvii
Stephens ftoc.tex V2 - 10/03/2008
Contents
Determining Security Needs
Determining Data Integrity Needs
236
236
Write Use Cases
Write the Requirements Document
Demand Feedback
Summary
Exercises
238
242
243
244
244
Chapter 12: Building a Data Model
245
Semantic Object Modeling
245
Building an Initial Semantic Object Model
Improving the Semantic Object Model
Entity-Relationship Modeling
245
248
250
Building an ER Diagram
Building a Combined ER Diagram
Improving the Entity-Relationship Diagram
Relational Modeling
Putting It All Together
Summary
Exercises
250
252
254
256
259
260
261
Chapter 13: Extracting Business Rules
Identifying Business Rules
263
263
Courses
CustomerCourses
Customers
Pets
Employees
Orders
OrderItems
InventoryItems
TimeEntries
Shifts
Persons
Phones
Vendors
264
266
267
267
267
267
268
268
268
269
269
269
269
Drawing a New Relational Model
Summary
Exercises
270
270
271
xviii
www.it-ebooks.info
4:13am
Page xviii
Stephens
ftoc.tex V2 - 10/03/2008
4:13am
Contents
Chapter 14: Normalization and Refinement
273
Improving Flexibility
Verifying First Normal Form
Verifying Second Normal Form
273
275
278
Pets
TimeEntries
279
280
Verifying Third Normal Form
Summary
Exercises
Part IV:
281
283
284
Implementing Databases
(with Examples in
Access and MySQL)
Chapter 15: Microsoft Access
287
Understanding Access
Getting Started
Defining Relationships
Creating Field Constraints
Creating Table Constraints
Creating Queries
287
288
293
296
298
301
Query Design View
SQL View
304
306
Summary
Exercises
308
308
Chapter 16: MySQL
313
Installing MySQL
Using MySQL Command Line Client
Executing SQL Scripts
Using MySQL Query Browser
313
314
318
319
Executing Queries
Editing Data
Creating and Modifying Databases
Using Scripts
Getting Syntax Help
320
320
321
327
329
Using MySQL Workbench
330
Loading Scripts
Creating EER Diagrams
330
331
xix
www.it-ebooks.info
Page xix
Stephens ftoc.tex V2 - 10/03/2008
Contents
Editing Databases
Defining Triggers
Exporting Scripts
333
334
336
Summary
Exercises
Part V:
338
338
Advanced Topics
Chapter 17: Introduction to SQL
345
Background
Finding More Information
Standards
Basic Syntax
Command Overview
CREATE TABLE
CREATE INDEX
DROP
INSERT
SELECT
345
346
346
347
348
350
355
356
357
358
SELECT Clause
FROM Clause
WHERE Clause
GROUP BY Clause
ORDER BY Clause
358
359
362
362
363
UPDATE
DELETE
Summary
Exercises
364
365
366
366
Chapter 18: Building Databases with SQL Scripts
369
Why Bother with Scripts?
Script Categories
369
370
Database Creation Scripts
Basic Initialization Scripts
Data Initialization Scripts
Cleanup Scripts
Saving Scripts
370
370
370
371
371
Ordering SQL Commands
Summary
Exercises
371
376
377
xx
www.it-ebooks.info
4:13am
Page xx
Stephens
ftoc.tex V2 - 10/03/2008
4:13am
Contents
Chapter 19: Database Maintenance
Backups
Data Warehousing
Repairing the Database
Compacting the Database
Performance Tuning
Summary
Exercises
379
379
382
383
383
383
386
387
Chapter 20: Database Security
The Right Level of Security
Passwords
389
389
390
Single-Password Databases
Individual Passwords
Operating System Passwords
Good Passwords
Privileges
Initial Configuration and Privileges
Too Much Security
Physical Security
Summary
Exercises
Appendix A: Exercise Solutions
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
390
390
391
391
392
398
398
399
400
401
403
403
408
411
413
417
424
430
434
436
440
442
446
449
451
454
xxi
www.it-ebooks.info
Page xxi
Stephens
ftoc.tex V2 - 10/03/2008
Contents
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
454
454
457
459
460
Appendix B: Sample Database Designs
Books
DVD and Movies
Music and CDs
Documents
Customer Orders
Employee Shifts and Timesheets
Employees, Projects, and Departments
Employee Skills and Qualifications
Identical Object Rental
Distinct Object Rental
Students, Courses, and Grades
Teams
Individual Sports
Vehicle Fleets
Contacts
Passengers
Recipes
467
468
470
471
472
472
473
473
475
476
476
478
479
480
480
483
483
485
Glossary
487
Index
497
xxii
www.it-ebooks.info
4:13am
Page xxii
Stephens f04.tex
V3 - 10/01/2008
3:41am
Introduction
It has been estimated that more than 80 percent of all computer programming is database-related. This
is certainly easy to believe. After all, a database can be a powerful tool for doing exactly what computer
programs do best: store, manipulate, and display data.
Even many programs that seem at first glance to have little to do with traditional business-oriented
data use databases to make processing easier. In fact, looking back on more than 20 years of software
development experience, I’m hard pressed to think of a single non-trivial application that I’ve worked on
that didn’t use some kind of database.
Not only do databases play a role in many applications, but they also often play a critical role. If the data
is not properly stored, it may become corrupted and the program will be unable to use it meaningfully.
If the data is not properly organized, the program may be unable to find what it needs in a reasonable
amount of time.
Unless the database stores its data safely and effectively, the application will be useless no matter how
well-designed the rest of the system may be. The database is like the foundation of a building: without a
strong foundation, even the best crafted building will fail, sometimes spectacularly (the Leaning Tower
of Pisa notwithstanding).
With such a large majority of applications relying so heavily on databases, you would expect everyone involved with application development to have a solid, formal foundation in database design and
construction. Everyone including database designers, application architects, programmers, database
administrators, and project managers should ideally understand what makes a good database design.
Even an application’s key customers and users could benefit from understanding how databases work.
Sadly that is usually not the case. Many IT professionals have learned what they know about databases
through rumor, trial-and-error, and painful experience. Over the years, some develop an intuitive feel
for what makes a good database design but they may still not understand the reasons why a design is
good or bad, and they may leave behind a trail of rickety, poorly constructed programs built on shaky
database foundations.
This book provides the tools you need to design a database. It explains how to determine what should
go in a database and how a database should be organized to ensure data integrity and a reasonable
level of performance. It explains techniques for designing a database that is strong enough to store data
safely and consistently, flexible enough to allow the application to retrieve the data it needs quickly and
reliably, and adaptable enough to accommodate a realistic amount of change.
www.it-ebooks.info
Page xxiii