Absolute beginners guide to databases

337 82 0
Absolute beginners guide to databases

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Databases 201 West 103rd Street, Indianapolis, Indiana 46290 Absolute Beginner’s Guide to Databases Associate Publisher Copyright ©2002 by Que Dean Miller All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Acquisitions Editor International Standard Book Number: 0-7897-2569-X Jim Booth Library of Congress Catalog Card Number: 2001098154 Managing Editor Printed in the United States of America Thomas F Hayes First Printing: March 2002 Project Editor 05 04 03 02 Jenny Watson Development Editor Maureen A McDaniel Technical Editor Tricia Liebig Production Editor Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Que cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an “as is” basis The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book Maribeth Echard Indexer Ken Johnson Proofreaders Juli Cook Bob LaRoche Team Coordinator Cindy Teeters Interior Designer Kevin Spear Cover Designer Trina Wurst Page Layout Michelle Mitchell Contents at a Glance Introduction, Part I Database Basics, An Introduction to Databases, The Anatomy of a Real Database, 19 Part II Designing and Building Your First Database, 43 Part III An Introduction to Database Design, 45 Database Design Continued: An Introduction to Normalization, 69 Using Access to Build the Time Entry and Billing Database, 95 Maintaining Your Database— An Introduction to Database Integrity, 119 Maintaining Integrity Through Data Validation Rules, 121 The Basics of Referential Integrity, 147 Part IV Using Your Database to Provide Information—An Introduction to SQL, 157 SQL Basics, 159 SQL—Going Beyond the Basics, 187 Making SQL Queries a Part of Your Database, 217 10 Part V 11 12 Putting Your Database to Work—Building a Simple Access Database Application, 235 Building the User Interface Components, 237 Providing Useful Output: An Introduction to Creating and Designing Reports, 263 Appendixes A B C D E The Structure of the TEB Database, 277 TEB Referential Integrity Rules, 283 Glossary, 285 Database-Oriented Periodicals, 295 Web-Based Resources, 297 Index, 299 Table of Contents Introduction II Designing and Building Your First Database I Database Basics An Introduction to Database Design An Introduction to Databases What Is a Database? 45 Your Project: A Time Entry and Billing Database 46 How Databases Are Used Typical Database Management Systems Used Today 10 Key Database Terminology 11 Database 12 Tables and Entities 12 Fields, Columns, and Attributes Normalization 12 Rows and Records 12 Primary Key 13 Introduction to Database Modeling 50 What Does a Database Model Look Like? 51 Creating Your First Model 52 Creating a Physical Database from the Logical Database Model 60 Creating a Logical Database Model from a Physical Database 61 12 The Relational Database Model: An Overview 13 Database-Related Careers 17 Database Administrator 17 Database Applications Programmer Database Analyst 18 What You Have Learned 17 Model the Time Entry and Billing Database 62 Editing the Text 63 Refining the Design 63 What You Have Learned 66 18 The Anatomy of a Real Database 19 An Introduction to Microsoft Access 20 The Sample Northwind Traders Database The Database’s Relationships 22 Overview of the Database’s Components 26 What You Have Learned Determine the Requirements of the Database 47 Interviews 47 Business Forms and Documents 48 Existing Systems 49 40 Database Design Continued: An Introduction to Normalization 69 What Does It Mean to Normalize a Database? 70 22 Steps to Normalize Your Data Model 71 First Normal Form: Eliminating Repeating Groups 72 Second Normal Form: Eliminating Redundant Data 73 vi ABSOLUTE BEGINNER’S GUIDE TO DATABASES Third Normal Form: Eliminating Columns Not Dependent on Keys 79 Fourth and Fifth Normal Forms 81 Normalization: Some Final Thoughts 83 Denormalize Data—When Does It Make Sense to Break the Rules? 83 Implement Row-Level Rules 143 Row-Level Properties 143 What You Have Learned 145 The Basics of Referential Integrity What Is Referential Integrity? Normalization Applied—Review the TEB Database and Refine the Design 84 Identifying New Columns and Tables 85 Reviewing the TEB Model 91 What You Have Learned 93 Using Access to Build the Time Entry and Billing Database 95 Automatically Generate the Database from the TEB Model 96 Use the Design to Create the Time Entry and Billing Database 103 Creating the Database 103 Creating Tables and Columns 106 Creating Relationships 112 What You Have Learned 117 III Maintaining Your Database—An Introduction to Database Integrity Maintaining Integrity Through Data Validation Rules 121 An Overview of How Validation Rules Work in Databases 122 Implement Field-Level Rules 123 Field-Level Properties 123 148 Why Maintaining Referential Integrity Is Important 148 How Referential Integrity Works 149 Establishing Referential Integrity Rules for the TEB Database 150 Restricted Deletes 151 Restricted Inserts 152 Cascading Deletes 153 Cascading Updates 153 What You Have Learned A Brief Review of the Access Database Designer 99 Main Database Window 100 Designer Window 102 147 154 IV Using Your Database to Provide Information—An Introduction to SQL SQL Basics 159 SQL Overview 160 Interactively Working with SQL in Access 161 The DDL and DCL SQL Sublanguages 162 Statement 164 Selecting Specific Fields 165 Renaming Fields with the As Clause Combining Field Data 167 Top n Select Statements 169 Select Filter Results I: Use the Where Clause Organize Output I: Use the Order By Clause 172 Compound Sort Orders 173 166 170 vii CONTENTS Combine Multiple Tables: Use the Join Statement 176 Inner Joins 177 Left Outer Joins 180 Right and Full Outer Joins 182 Combine Multiple Resultsets: Use the Union Clause 184 What You Have Learned 186 Suppressing Columns 223 Adding a Sort Order 225 Sorting on Multiple Fields 226 Saving Your Query 227 Create Advanced Queries 228 Implementing Aggregate Functions and Groupings 230 Parameterized Queries 232 What You Have Learned SQL—Going Beyond the Basics Organize Output II: Use the Group Clause 188 By Use Aggregate Functions 190 The Count() Function 190 Advanced Operations: A Methodology for Putting It All Together 192 The Sum() Function 196 The Avg() Function 204 The Min() and Max() Functions 205 Filter Results II: Use the Having Clause 206 Filter Results III: Create Parameterized SQL Statements 207 Modify Data with the Insert, Update, and Delete Statements 210 The Insert Statement 210 The Update Statement 212 The Delete Statement 213 What You Have Learned 215 10 Making SQL Queries a Part of Your Database 217 An Overview of the Access Query Designer 218 Adding Select Fields 220 Adding Selection Criteria 221 234 187 V Putting Your Database to Work— Building a Simple Access Database Application 11 Building the User Interface Components 237 Overview of the Access Form Designer Create Forms for the TEB Application Client 239 Employee Form 256 Create a Main Menu Form What You Have Learned 238 239 258 262 12 Providing Useful Output: An Introduction to Creating and Designing Reports 263 Overview of the Access Report Designer 264 Create Reports for the TEB Application 265 Client Listing 265 Modifying the ClientListing Report in the Report Designer 271 Add Report Items to the Main Menu Form 272 What You Have Learned 275 A The Structure of the TEB Database B TEB Referential Integrity Rules C Glossary 285 D Database-Oriented Periodicals E Web-Based Resources Index 283 299 297 295 277 About the Author John V Petersen is president and founder of Main Line Software, Inc., a Philadelphia, Pennsylvania–based software application and database design firm MLSI development platforms include Visual FoxPro, Visual Basic, Access, SQL Server, and Microsoft’s newest development platform Visual Studio NET John earned an MBA from the Haub School of Business at St Joseph’s University in 1993 John is currently a 2L at the Rutgers University School of Law John has presented at many industry events including Microsoft Developer Days and Microsoft Tech-Ed John’s writing projects have included Visual FoxPro Enterprise Development and Hands-On Visual Basic Web Development from Prima Publishing, ADO Jumpstart MSDN Whitepaper, and numerous feature articles on application development and database design issues John has been an annual recipient of Microsoft’s Most Valuable Professional award since 1996 Dedication To my sons Karl and Keith You both make me proud in all that you I know you both will accomplish great things I love you both very much To my wife Evelyn Thank you again for all of the love and support you have given me over the years, especially now in light of my “starting over” in a new career in law Acknowledgments I want to first thank Jenny Watson for presenting this project to me Initially, the project had lots of starts and stops due to my hectic work schedule Jenny believed in two things: the project and my doing the project Thank you, Jenny, for your patience and support! An author is very lucky when he has a great development editor like Maureen McDaniel Whenever I have had a question or concern, Maureen was always right there, ready with an answer and guidance Thank you, Maureen, for making this a fun and rewarding project I have had the fortune of Jim Booth’s friendship and guidance for many years now I was very happy that he accepted the technical editing assignment for this project Jim is one of the smartest people I know and this project has benefited from his expertise, wisdom, and guidance 310 RULES Validation Rule, 144 Validation Text, 144-145 S Save As dialog box (Access Database Designer), 108 saving queries, 227 tables, 107 Second Normal Form, 73-78 Select statements (SQL), 164-165 Shape menu (Visio), 59 shapes (database title), 63 Show Table dialog box (Access Database Designer), 112-113 sort orders, 225 sorting multiple fields, 226 SQL (Structured Query Language) window ANSI-SQL 92, 160 clauses As, 198 From, 192-193 Group By, 188-189, 196, 202 Having, 206 Join, 193 Order By, 202 Where, 204, 206, 212-214 compound sort orders, 173, 175 CRUD (Create, Update, and Delete) operations, 160 Distinct clause, 178 fields combining data, 167-169 renaming, 166, 198 selecting, 165 full outer joins, 182-184 functions aggregate, 190 Avg(), 204 Count(), 190-191, 195 Min() and Max(), 205, 211 Sum(), 196-197 joins full outer, 182-184 inner, 177-178 left outer, 180-181 right, 182-184 limiting results, 181 Order By Clause, 172-173 statements Delete, 213-214 Insert, 210-211 parameterized, 207-208 Select, 164-165 Update, 212 sublanguages DCL (Data Control Language), 160-163 DDL (Data Definition Language), 160-163 DML (Data Manipulation Language), 160-163 tables combining, 176 returning data, 179-181 Top n Select statements, 169-170 Union clause, 184-185 Where Clause, 170-171 starting Access, 20-22 Startup dialog boxes (Access), 21 statements (SQL window) Delete, 213-214 Insert, 210-211 parameterized, 207-208 Update, 212 TEB strategic decisions, determining database requirements, 48 Structured Query Language See SQL (Structured Query Language) structures queries, 31 tables Case, 88 Contact, 87-88 Employee tables, 86 Invoice, 91 TimeEntryDetail tables, 90 WorkCategory, 91 Sum() functions (SQL), 196-197 surrogate keys, 76 symbols Design Symbol Toolbox (Visio), 54-56 relationships, 56 systems DBMS (database management system), 10-11 existing, 49 T Table Datalist View, 39 Table Designer (Lookup tab), 40 Table wizards (Access Database Designer), 106 tables, 8, 26 Case, 88 child, 23 Client, 86 combining (SQL), 176 Contact, 87-88 Court, 89 creating, 106 defining, 12 Department, 86 311 dialog boxes (New Table), 106-107 Employee, 85-86 EmployeeClass, 86 FieldName property, 29 Invoice, 91 junction, 24 many-to-many resolver, 85 multitable queries, 35 normalization, 12 parent, 23 relationships Access Database Relationship Builder, 114 creating, 112-114 Relationships View, 51 returning data (SQL), 179-181 rows, 12 saving, 107 Table Datalist View, 39 TimeEntryDetail, 89-91 views, 15 WorkCategory, 90-91 tabs Attributes, 56 Databases (Access Database Designer), 103 General, 56 General (Access Database Designer), 103-104 Lookup, 28, 40-41 tactical decisions, determining database requirements, 48 TEB (Time Entry and Billing) databases models, 84-85, 96 tables Case, 88 Client, 86 Contact, 87-88 Court, 89 Department, 86 Employee, 85-86 312 TEB EmployeeClass, 86 Invoice, 91 TimeEntryDetail, 89-91 WorkCategory, 90-91 TEB.LDB files, 105 TEB.MDB files, 105 text editing, 63 highlighting, 63 Text data types, 29 Third Normal Form, 79-80 TimeEntryDetail tables, 89-91 toolboxes Design Symbol (Visio), 54-56 Design Symbol toolbox, 63 tools, database design, 51 Tools menu (Access Database Designer), 112, 116 Top n Select statements (SQL), 169-170 U–V understanding databases, Unicode Compression, 30 Union clause (SQL), 184-185 Update Foreign Keys, 59 validations See rules View button, 27, 33, 41 views, 15 Datalist, 27, 30, 37 Datasheet (Access Database Designer), 27, 106, 151 Design (Access Database Designer), 27, 106-107 Products by Category Report, 38 Products Form, 41 Print Preview, 38 relationship, 22 Relationships, 51 Table Datalist, 39 Visible Analyst Database Engineer See VADBE (Visible Analyst Database Engineer) Visio, 51-52 Create Database Wizard, 60, 96-97 Design Surface, 52-53 Design Symbol Toolbox, 55-56 Designer, 52-53 Diagram files, 97 entities, creating, 55-56 Map Database Wizard, 61 Shape menu, 59 Web site, 51 vsd diagram files (Visio), 97 W Update statements (SQL), 212 uses of databases, 9-10 Using Microsoft Access 2000, 20 VADBE (Visible Analyst Database Engineer), 52 Validation Rule property, 30, 139-140, 144 Validation Text Property, 30, 141-145 Web sites Access, 20 ErWin (Computer Associates), 52 Microsoft Knowledge Base, 20 MSDN KB (Microsoft Developer Network Knowledge Base), 105 VADBE (Visible Analyst Database Engineer), 52 Visio, 51 xCase (Resolution), 51-52 YES/NO DATA TYPES Where Clause (SQL), 170-171, 204-206, 212-214 windows combining data, 167-169 renaming, 166 returning data, 179-181 Top n Select statement, 169-170 Union clause, 184-185 Update statements, 212 Where Clause, 170-171 selecting, 165 full outer joins, 182-184 inner joins, 177-178 Insert statements, 210-211 left outer joins, 180-181 limiting results, 181 Min() and Max() functions, 205, 211 Order By Clause, 172-173 parameterized statements, 207-208 renaming fields, 198 right joins, 182-184 Select statement, 164-165 Sum() functions, 196-197 SQL aggregate functions, 190 As clause, 198 Avg() functions, 204 combining tables, 176 compound sort orders, 173-175 Count() functions, 190-191, 195 Delete statements, 213-214 Distinct clause, 178 From clause, 192-193 Group By clause, 188-189, 196, 202 Having clause, 206 Join clause, 193 Order By clause, 202 Where clause, 204-206, 212-214 Windows Clipboard, 55 313 wizards Command Button, 274 Create Database Wizard (Visio), 60, 96-97 Database Wizard (Visio), 61 Form Wizard adding custom buttons, 249, 252 creating BusinessClient forms, 246 creating employee forms, 256-257 creating IndividualClient forms, 244, 253-254 modifying layout, 248 Import Table (Access Database Designer), 106 Input Mask, 134 Link Table (Access Database Designer), 107 Map Database Wizard, 62 Query Wizard, 240-242 Report Wizard, 267-269 Table (Access Database Designer), 106 WorkCategory tables, 90-91 X–Z xCase (Resolution), 51-52 Yes/No data types, 29 Hey, you’ve got enough worries Don’t let IT training be one of them Get on the fast track to IT training at InformIT, your total Information Technology training network www.informit.com ■ Hundreds of timely articles on dozens of topics ■ Discounts on IT books from all our publishing partners, including Que Publishing books from the InformIT Free Library with IT experts ■ Free, unabridged “Expert Q&A”—our live, online chat Faster, easier certification and training from our Web- or classroom-based training programs ■ ■ ■ ■ Current IT news Career-enhancing resources InformIT is a registered trademark of Pearson Copyright ©2001 by Pearson Copyright ©2001 by Que Corporation ■ Software downloads Using Special Edition Using Microsoft Office XP The One Source for Comprehensive Solutions™ Ed Bott and Woody Leonhard 0-7897-2513-4 $39.99 US The one-stop shop for serious users, Special Edition Using offers readers a thorough understanding of software and technologies Intermediate to advanced users get detailed coverage that is clearly presented and to the point Other Special Edition Using Titles Special Edition Using the Internet and the Web Michael Miller 0-7897-2613-0 $29.99 US Special Edition Using Oracle 11i Boss Corporation 0-7897-2670-x $75.00 US Special Edition Using XML Schemas David Gulbransen 0-7897-2607-6 $39.99 US Special Edition Using MS-DOS 6.22, Third Edition Special Edition Using Visual Basic.NET Jim Cooper 0-7897-2573-8 $49.99 US Brian Siler and Jeff Spotts 0-7897-2572-x $39.99 US Special Edition Using Microsoft Windows XP Professional Bob Cowart 0-7897-2628-9 $49.99 US Special Edition Using Enterprise JavaBeans 2.0 Special Edition Using Microsoft Access 2002 Chuck Cavaness and Brian Keeton 0-7897-2567-3 $39.99 US Roger Jennings 0-7897-2510-x $49.99 US www.quepublishing.com All prices are subject to change Other Related Titles Microsoft SQL Server 2000 Database Development from Scratch Rob Hawthorne Absolute Beginner’s Guide to Networking Joe Habraken 0-7897-2545-2 $24.99 US Microsoft Office XP 8-in-1 Joe Habraken 0-7897-2509-6 $29.99 US Web Site Design Goodies Joe Burns 0-7897-2485-5 $29.99 US Prototyping with Visual Basic Rod Stephens 0-7897-2447-2 $39.99 US Think Microsoft.NET Bart Depatrillo 0-7897-2595-9 $29.99 US Absolute Beginner’s Guide to Cable Internet Connections Mark Soper 0-7897-2705-6 $24.99 US Oracle 9i Development by Example Absolute Beginner’s Guide to Personal Firewalls Dan Hotka 0-7897-2671-8 $34.99 US Jerry Lee Ford 0-7897-2625-4 $24.99 US 0-7897-2578-9 $39.99 US Encyclopedia of Technology Terms Whatis?com 0-7897-2640-8 $29.99 US Absolute Beginner’s Guide to Programming Greg Perry 0-7897-2529-0 $24.99 US www.quepublishing.com All prices are subject to change Visit our Web site at www.quepublishing.com • New releases • Links to deep discounts • Full catalog of hot computer books • Source code • Author links and Web sites • Customer support ... cards, is stored in a database 10 ABSOLUTE BEGINNER’S GUIDE TO DATABASES It can be said that the construction of databases entails the process of turning disparate pieces of data into information... implementation of a database 2 ABSOLUTE BEGINNER’S GUIDE TO DATABASES Part I—Database Basics You need to crawl before you walk! What is a database? What are the different kinds of databases and how are... orders.ordernumber In other words, you don’t need to search through a string of characters to locate the order number 14 ABSOLUTE BEGINNER’S GUIDE TO DATABASES Null values (distinct from the empty

Ngày đăng: 04/03/2019, 11:11

Từ khóa liên quan

Mục lục

  • Absolute Beginner's Guide to Databases

    • Copyright

    • Contents at a Glance

    • Table of Contents

    • INTRODUCTION

    • DATABASE BASICS I PART

      • 1 AN INTRODUCTION TO DATABASES

        • What Is a Database?

        • How Databases Are Used

        • Typical Database Management Systems Used Today

        • Key Database Terminology

        • The Relational Database Model: An Overview

        • Database-Related Careers

        • What You Have Learned

        • 2 THE ANATOMY OF A REAL DATABASE

          • An Introduction to Microsoft Access

          • The Sample Northwind Traders Database

          • What You Have Learned

          • DESIGNING AND BUILDING YOUR FIRST DATABASE II PART

            • 3 AN INTRODUCTION TO DATABASE DESIGN

              • Your Project: A Time Entry and Billing Database

              • Determine the Requirements of the Database

              • Introduction to Database Modeling

              • Model the Time Entry and Billing Database

              • What You Have Learned

              • 4 DATABASE DESIGN CONTINUED: AN INTRODUCTION TO NORMALIZATION

                • What Does It Mean to Normalize a Database?

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan