Since then he has been continuously employed in a widevariety of information technology positions, including programmer, programmer/analyst, systems architect, project manager, senior da
Trang 2DATABASES DEMYSTIFIED
Composite Default screen
Trang 3Composite Default screen
This page intentionally left blank.
Trang 4Seoul Singapore Sydney Toronto
Composite Default screen
Trang 5Composite Default screen
Copyright © 2004 by The McGraw-Hill Companies All rights reserved Manufactured in the United States of America Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher
0-07-146960-5
The material in this eBook also appears in the print version of this title: 0-07-225364-9
All trademarks are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps McGraw-Hill eBooks are available at special quantity discounts
to use as premiums and sales promotions, or for use in corporate training programs For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc (“McGraw-Hill”) and its licensors reserve all rights in and to the work Use of this work is subject to these terms Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited Your right to use the work may be terminated if you fail to comply with these terms
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES
OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO
BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free Neither McGraw-Hill nor its licensors shall
be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom McGraw-Hill has no responsibility for the content of any information accessed through the work Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise
DOI: 10.1036/0071469605
Trang 6To everyone from whom I have learned so much about so many things, including the many teachers, students, and co-workers
I have had the pleasure of knowing.
Composite Default screen
Trang 7ABOUT THE AUTHOR
Andrew J (Andy) Oppel is a proud graduate of The Boys’ Latin School of land and of Transylvania University (Lexington, KY) where he earned a BA in com-puter science in 1974 Since then he has been continuously employed in a widevariety of information technology positions, including programmer, programmer/analyst, systems architect, project manager, senior database administrator, databasegroup manager, consultant, database designer, and data architect In addition, he hasbeen a part-time instructor with the University of California (Berkeley) Extensionfor over 20 years, and received the Honored Instructor Award for the year 2000 Histeaching work has included developing two courses for UC Extension, “Concepts ofDatabase Management Systems” and “Introduction to Relational Database Man-agement Systems.” He also earned his Oracle 9i Database Associate certification in
Mary-2003 He is currently employed as the principal data architect for Ceridian, a leadingprovider of human resource solutions Aside from computer systems, Andy enjoysmusic (guitar and vocals), amateur radio (Pacific Division vice director, AmericanRadio Relay League), and soccer (referee instructor, U.S Soccer)
Andy has designed and implemented hundreds of databases for a wide range ofapplications, including medical research, banking, insurance, apparel manufactur-ing, telecommunications, wireless communications, and human resources His da-tabase product experience includes IMS, DB2, Sybase, Microsoft SQL Server,Microsoft Access, MySQL, and Oracle (versions 7, 8, 8i, and 9i)
Composite Default screen
Trang 8CONTENTS AT A GLANCE
CHAPTER 2 Exploring Relational Database Components 25
CHAPTER 6 Logical Database Design Using
CHAPTER 9 Connecting Databases to the Outside World 227
CHAPTER 12 Databases for Online Analytical Processing 293
Trang 9Composite Default screen
This page intentionally left blank.
Trang 10The Object-Oriented Model 15The Object-Relational Model 16
CHAPTER 2 Exploring Relational Database Components 25
Conceptual Database Design Components 26
Composite Default screen
For more information about this title, click here
Trang 11QBE: The Roots of Forms-Based Queries 52Getting Started in Microsoft Access 52The Microsoft Access Relationships Panel 55The Microsoft Access Table Design View 57Creating Queries in Microsoft Access 59Example 3-1: List All Customers 62Example 3-2: Choosing Columns to Display 63Example 3-3: Sorting Results 64Example 3-4: Advanced Sorting 66Example 3-5: Choosing Rows to Display 66Example 3-6: Compound Row Selection 68Example 3-7: Using Not Equal 70Example 3-8: Joining Tables 70Example 3-9: Limiting Join Results 72Example 3-10: Outer Joins 75Example 3-11: Multiple Joins;
Trang 12Demystified / Databases Demystified / Oppel/ 225364-9 / FM
Getting Started with Oracle SQL 91
Finding Database Objects Using Catalog Views 97Viewing Database Objects Using
Oracle Enterprise Manager 98Data Query Language (DQL):
Example 4-1: Listing All Employees 100Example 4-2: Limiting Columns to Display 100Example 4-3: Sorting Results 102Choosing Rows to Display 103
Data Manipulation Language (DML) 114Transaction Support
Data Definition Language (DDL) Statements 118The CREATE TABLE Statement 118The ALTER TABLE Statement 119The CREATE VIEW Statement 121The CREATE INDEX Statement 121
Data Control Language (DCL) Statements 122
Trang 13xii Databases Demystified
Demystified / Databases Demystified / Oppel/ 225364-9 / FM
Applying the Normalization Process 148
First Normal Form: Eliminating
TLA University Academic Tracking 164Composite Default screen
Trang 14Computer Books Company 170
Entity Relationship Modeling 180
The Function Hierarchy Diagram 192
Relating Entities and Processes 196
Integrating Business Rules and Data Integrity 214
Referential (Foreign Key) Constraints 216
Trang 15xiv Databases Demystified
Demystified / Databases Demystified / Oppel/ 225364-9 / FM
Connecting Databases to the Web 235Introduction to the Internet and the Web 236Components of the Web “Technology Stack” 238Invoking Transactions from Web Pages 239Connecting Databases to Applications 240Connecting Databases via ODBC 240Connecting Databases to Java Applications 241
Other Client Considerations 257
Database Security Architectures 259
Trang 17Composite Default screen
This page intentionally left blank.
Trang 18I owe much to my parents for providing me with an excellent education and a love of
both learning and teaching I credit The Boys’ Latin School of Maryland and the late
Jack H Williams, headmaster, with teaching me to write effectively And I credit
Transylvania University and Dr James E Miller for introducing me to the fascinating
world of information systems and providing me with the tools for continuous learning
I’d like to thank the wonderful people at McGraw-Hill/Osborne for the opportunity to
write my first book and for their excellent support during the writing process Finally,
my thanks to my wife Laurie and our sons Keith and Luke for their support, patience,
and understanding during the long hours it took to produce this book
Composite Default screen
Trang 19Composite Default screen
This page intentionally left blank.
Trang 20Thirty years ago, databases were found only in special research laboratories where
computer scientists struggled with ways to make them efficient and useful, and
pub-lished their findings in countless research papers Today databases are a ubiquitous
part of the information technology (IT) industry and business in general We directly
and indirectly use databases every day—banking transactions, travel reservations,
employment relationships, web site searches, purchases, and most other
transac-tions are recorded in and served by databases
As with many fast-growing technologies, industry standards have lagged behind
the development of database technology, resulting in a myriad of commercial
prod-ucts, each following a particular software vendor’s vision Moreover, a number of
different database models have emerged, with the relational model being the most
prevalent Databases Demystified examines all of the major database models,
in-cluding hierarchical, network, relational, object-oriented, and object-relational
However, Databases Demystified concentrates heavily upon the relational and
ob-ject-relational models because these are the mainstream of the IT industry and will
likely remain so in the foreseeable future
The most significant challenge in implementing a database is designing the
struc-ture of the database correctly Without a thorough understanding of the problem the
database is intended to solve, and without knowledge of the best practices for
orga-nizing the required data, the implemented database becomes an unwieldy beast that
requires constant attention Databases Demystified focuses on transformation of
re-quirements into a working database model with special emphasis on a process called
normalization, which has proven to be an effective technique for designing
rela-tional databases In fact, normalization can be applied successfully to other database
models And, in keeping with the notion that you cannot design an automobile if you
Composite Default screen
Trang 21have never driven one, the SQL language is introduced so that the reader may
“drive” a database before delving into the details of designing one
I’ve drawn on my extensive experience as a database designer, administrator, andinstructor to provide you with this self-help guide to the fascinating and complexworld of database technology Examples are included using both Microsoft Accessand Oracle Publicly available sample databases supplied by these vendors (theMicrosoft Access Northwind database and the Oracle Human Resources databaseschema) are used in example figures whenever possible so that you may try the ex-amples directly on your own computer system A review quiz is provided at the end
of each chapter along with a comprehensive exam at the end of the book
If you have any comments, I’d like to hear from you
Andrew J (Andy) Oppelandy@andyoppel.comHonored instructor, University of California Berkeley ExtensionPrincipal data architect, Ceridian
Certified Oracle 9i Database Associate
xx Databases Demystified
Composite Default screen
Trang 22CHAPTER 1
Database Fundamentals
This chapter introduces fundamental concepts and definitions regarding databases,
including properties common to databases, prevalent database models, a brief
his-tory of databases, and the rationale for focusing on the relational model
Properties of a Database
A database is a collection of interrelated data items that are managed as a single unit
This definition is deliberately broad because there is so much variety across the
vari-ous software vendors that provide database systems Microsoft Access places the
entire database in a single data file, so an Access database can be defined as the file
that contains the data items Oracle Corporation defines their database as a
collec-tion of physical files that are managed by an instance of their database software
product An instance is a copy of the database software running in memory
Composite Default screen
Trang 232 Databases Demystified
Demystified / Databases Demystified / Oppel/ 225364-9 / Chapter 1
Microsoft SQL Server and Sybase define a database as a collection of data items thathave a common owner, and multiple databases are typically managed by a single in-stance of the database management software This can be quite confusing if youwork with multiple products because, for example, a database as defined by MicrosoftSQL Server and Sybase is exactly what Oracle Corporation calls a schema
A database object is a named data structure that is stored in a database The cific types of database objects supported in a database vary from vendor to vendorand from one database model to another Database model refers to the way in which
spe-a dspe-atspe-abspe-ase orgspe-anizes its dspe-atspe-a to pspe-attern the respe-al world The most common dspe-atspe-abspe-asemodels are presented in “Prevalent Database Models,” later in this chapter
A file is a collection of related records that are stored as a single unit by an ing system Given the unfortunately similar definitions of files and databases, howcan we make a distinction? A number of Unix operating system vendors call theirpassword file a “database,” yet database experts will quickly point out that, in fact, it
operat-is not Clearly, we need a bit more rigor in our definitions The answer lies in an derstanding of certain characteristics or properties that databases possess that ordi-nary files do not, including the following:
un-• Management by a Database Management System (DBMS)
• Layers of data abstraction
• Physical data independence
• Logical data independenceThese properties are discussed in the following subsections
The Database Management System (DBMS)
The Database Management System (DBMS) is software provided by the databasevendor Software products such as Microsoft Access, Oracle, Microsoft SQLServer, Sybase, DB2, INGRES, and MySQL are all DBMSs If it seems odd to youthat the acronym used is DBMS instead of merely DMS, keep in mind that the term
“database” was originally written as two words, and by convention has become asingle compound word
The DBMS provides all the basic services required to organize and maintain thedatabase, including the following:
• Moving data to and from the physical data files as needed
• Managing concurrent data access by multiple users, including provisions toprevent simultaneous updates from conflicting with one another
Composite Default screen