Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

SQL for Microsoft Access
PREMIUM
Số trang
359
Kích thước
7.4 MB
Định dạng
PDF
Lượt xem
1393

SQL for Microsoft Access

Nội dung xem thử

Mô tả chi tiết

SQL

for

Microsoft®

Access

Cecelia L. Allison

& Neal A. Berkowitz

Wordware Publishing, Inc.

Library of Congress Cataloging-in-Publication Data

Allison, Cecelia.

SQL for Microsoft access / by Cecelia L. Allison and Neal A. Berkowitz.

p. cm.

Includes index.

ISBN-13: 978-1-55622-092-0

ISBN-10: 1-55622-092-8 (pbk.)

1. SQL (Computer program language). 2. Microsoft Access. I. Berkowitz, Neal.

II. Title.

QA76.73.S67A44 2005

005.13'3--dc22 2005017158

CIP

© 2005, Wordware Publishing, Inc.

All Rights Reserved

2320 Los Rios Boulevard

Plano, Texas 75074

No part of this book may be reproduced in any form or by

any means without permission in writing from

Wordware Publishing, Inc.

Printed in the United States of America

ISBN-13: 978-1-55622-092-0

ISBN-10: 1-55622-092-8

10 9 8 7 6 5 4 3 2 1

0506

Microsoft is a registered trademark of Microsoft Corporation in the United States and/or other countries.

Other brand names and product names mentioned in this book are trademarks or service marks of their

respective companies. Any omission or misuse (of any kind) of service marks or trademarks should not be

regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used

by companies, manufacturers, and developers as a means to distinguish their products.

This book is sold as is, without warranty of any kind, either express or implied, respecting the contents of

this book and any disks or programs that may accompany it, including but not limited to implied warranties for

the book’s quality, performance, merchantability, or fitness for any particular purpose. Neither Wordware

Publishing, Inc. nor its dealers or distributors shall be liable to the purchaser or any other person or entity with

respect to any liability, loss, or damage caused or alleged to have been caused directly or indirectly by this book.

All inquiries for volume purchases of this book should be addressed to Wordware

Publishing, Inc., at the above address. Telephone inquiries may be made by calling:

(972) 423-0090

To my parents, Willie A. Coney and Rosa D. Coney, my loving

husband, John F. Allison, and my daughter, Kayla Desiree Allison.

You each played a special role in inspiring me to reach for the

stars, stay focused, and work hard. I love you!

Cecelia L. Allison

To my wife, Deborah, who puts up with my idiosyncrasies and is

always there for me. When we got married she promised that I

would never be bored, and she has definitely exceeded that prom￾ise. She is the love of my life and, while I don’t say it often enough,

I hope that she knows it.

Neal A. Berkowitz

iii

This page intentionally left blank.

Contents

Acknowledgments .............................. xiii

Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Chapter 1 The Relational Database Structure ...........1

Introduction ..................................1

Early Forms of Data Storage .........................3

The Relational Database Structure ......................4

Tables ....................................4

Keys. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

The Planning Stage ..............................6

Data Modeling ...............................7

Entities and Relationships .......................7

Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Client/Server Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Database Management Systems . . . . . . . . . . . . . . . . . . . . . . . 11

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Chapter 2 Structured Query Language and Microsoft Access . . . 15

Structured Query Language . . . . . . . . . . . . . . . . . . . . . . . . . 16

SQL Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

SQL Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

SQL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

The Power of SQL in Microsoft Access . . . . . . . . . . . . . . . . . . . 18

The Query Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

The Query Design Tool and SQL View. . . . . . . . . . . . . . . . . . 19

Opening Microsoft Access and Switching to SQL View. . . . . . . . . . . 20

Opening Microsoft Access . . . . . . . . . . . . . . . . . . . . . . . . 20

Switching to SQL View . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Chapter 3 Creating Tables and Inserting Records. . . . . . . . . 25

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

The Data Definition Language Component . . . . . . . . . . . . . . . . . 26

CREATE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 27

Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

NULL/NOT NULL Constraint . . . . . . . . . . . . . . . . . . . . . . 32

PRIMARY KEY Constraint . . . . . . . . . . . . . . . . . . . . . . . . 32

Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

v

FOREIGN KEY Constraint . . . . . . . . . . . . . . . . . . . . . . . . 34

UNIQUE Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Adding Constraints to Existing Tables . . . . . . . . . . . . . . . . . . 36

Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

Example 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Constraint Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Inserting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Example 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Inserting Data without Specifying Column Names . . . . . . . . . . . 40

Example 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Inserting NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Example 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Copying Records from One Table to an Existing Table . . . . . . . . . 42

Example 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Copying Records from One Table to a New Table Simultaneously . . . 43

Example 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Updating Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Example 10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Deleting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Example 11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Chapter 4 Retrieving Records . . . . . . . . . . . . . . . . . . . 49

The SELECT Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . 50

Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

The ORDER BY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Sorting in Descending Order . . . . . . . . . . . . . . . . . . . . . . . 56

Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Sorting in Ascending Order. . . . . . . . . . . . . . . . . . . . . . . . 57

Example 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

Sorting Multiple Columns . . . . . . . . . . . . . . . . . . . . . . . . 58

Example 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Sorting Using Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 59

Example 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

Example 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Handling Duplicate Values . . . . . . . . . . . . . . . . . . . . . . . . . . 61

The DISTINCT Keyword . . . . . . . . . . . . . . . . . . . . . . . . . 61

Example 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

The DISTINCTROW Keyword . . . . . . . . . . . . . . . . . . . . . . 63

The TOP Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

Example 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Example 10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

The TOP PERCENT Keywords . . . . . . . . . . . . . . . . . . . . . 66

vi

Contents 

Example 11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Example 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Creating an Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Example 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

Example 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Chapter 5 Filtering Retrieved Records. . . . . . . . . . . . . . . 73

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

The WHERE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

Operator Precedence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

The AND, OR, =, and < Operators . . . . . . . . . . . . . . . . . . . 77

Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

The LIKE Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

Example 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

Example 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Example 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Example 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Example 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Example 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

The BETWEEN Operator . . . . . . . . . . . . . . . . . . . . . . . . 84

Example 10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

The IN and NOT Operators. . . . . . . . . . . . . . . . . . . . . . . . 86

Example 11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

The IS NULL and IS NOT NULL Operators. . . . . . . . . . . . . . . 87

Example 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Chapter 6 Creating Calculated Fields . . . . . . . . . . . . . . . 91

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

Operators and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Using the AVG (), FIRST (), LAST (), SUM (), MAX (),

and MIN () Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

Using the COUNT () Function . . . . . . . . . . . . . . . . . . . . . . 99

Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

String Functions and Operations . . . . . . . . . . . . . . . . . . . . . . 100

vii

Contents

Use of the + and & . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Using the LEFT (), UCASE (), LEN (), and TRIM () Functions . . . . 103

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

Using the MID () and INSTR () Functions . . . . . . . . . . . . . . . 104

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 105

Inserting Dates into a Table . . . . . . . . . . . . . . . . . . . . . . . 107

Example 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

Using the FORMAT () Function. . . . . . . . . . . . . . . . . . . . . 108

Example 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

Using the DATE (), TIME (), MONTH (), DAY (),

and YEAR () Functions . . . . . . . . . . . . . . . . . . . . . . . . . 110

Example 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . 111

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Chapter 7 Grouping Data . . . . . . . . . . . . . . . . . . . . 115

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

The GROUP BY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . 116

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

Using the GROUP BY Clause with the ORDER BY Clause . . . . . . 120

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

The HAVING Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Using the HAVING Clause with the WHERE Clause . . . . . . . . . 123

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

Chapter 8 Creating Table Joins and Unions . . . . . . . . . . . 127

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

Table Joins — An Overview . . . . . . . . . . . . . . . . . . . . . . . . 128

Qualification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Inner Join. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Using the DISTINCTROW Keyword . . . . . . . . . . . . . . . . . . 133

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Self Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Nested Join. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

Right Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

Left Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

Example 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

viii

Contents 

UNION and UNION ALL Keywords . . . . . . . . . . . . . . . . . . . . 145

UNION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Example 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

UNION ALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Example 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Chapter 9 Creating Subqueries . . . . . . . . . . . . . . . . . 153

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Correlated and Non-Correlated Subqueries . . . . . . . . . . . . . . 154

The IN Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

The EXISTS Subquery . . . . . . . . . . . . . . . . . . . . . . . . . 158

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

The ANY and SOME Subqueries . . . . . . . . . . . . . . . . . . . . 161

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

The ALL Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Nested Subqueries. . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

Chapter 10 Creating Views . . . . . . . . . . . . . . . . . . . 169

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

Creating a View Using the CREATE VIEW Keywords in SQL-92 . . . . 172

Setting the SQL Version for a Current Database . . . . . . . . . . . . 172

Setting the SQL Version as the Default Setting for New Databases . . 173

Filtering a Record Through a View. . . . . . . . . . . . . . . . . . . . . 174

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

Updating a Record Through a View . . . . . . . . . . . . . . . . . . . . 175

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

Deleting a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

Chapter 11 Table Management and Indexes . . . . . . . . . . 179

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

Adding a Column to an Existing Table . . . . . . . . . . . . . . . . . . . 180

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

Changing a Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

ix

Contents

Setting a Default Value for a Column. . . . . . . . . . . . . . . . . . . . 183

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

Removing a Column from a Table . . . . . . . . . . . . . . . . . . . . . 184

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

Removing a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

Improving Data Retrieval Time Using Indexes . . . . . . . . . . . . . . 185

Index Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

Creating an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

Viewing and Editing Indexes . . . . . . . . . . . . . . . . . . . . . . 188

Deleting an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Example 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Chapter 12 Temporary Tables vs. Views . . . . . . . . . . . . . 191

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192

Creating a Temporary Table . . . . . . . . . . . . . . . . . . . . . . . . 194

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

Accessing the Temporary Table . . . . . . . . . . . . . . . . . . . . . . 195

Querying a Temporary Table . . . . . . . . . . . . . . . . . . . . . . . . 196

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

Indexing a Temporary Table . . . . . . . . . . . . . . . . . . . . . . . . 197

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

Updating a Temporary Table . . . . . . . . . . . . . . . . . . . . . . . . 198

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

Deleting a Temporary Table . . . . . . . . . . . . . . . . . . . . . . . . 199

Example 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

Chapter 13 Parameter Queries . . . . . . . . . . . . . . . . . 201

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

Parameter Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

Creating a Simple Query . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Creating a Parameter Query . . . . . . . . . . . . . . . . . . . . . . . . 203

Example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

Customizing Your Dialog Box . . . . . . . . . . . . . . . . . . . . . . . 205

Example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

Creating Multiple Prompts . . . . . . . . . . . . . . . . . . . . . . . . . 206

Example 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

Example 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

Using the LIKE Keyword to Prompt the User. . . . . . . . . . . . . . . 208

Example 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

x

Contents 

Prompting the User for Dates . . . . . . . . . . . . . . . . . . . . . . . 209

Example 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Creating a Button to Prompt the User . . . . . . . . . . . . . . . . . . . 210

Example 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

SQL Syntax for a Parameter Query in SQL View . . . . . . . . . . . . . 214

Example 9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

Chapter 14 Integrating SQL Script in VBA Code . . . . . . . . . 217

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Fixed Queries vs. “On-the-Fly” Queries. . . . . . . . . . . . . . . . . . 218

Filtered Recordsets for Forms . . . . . . . . . . . . . . . . . . . . . . . 222

Filtered Recordsets for Combo Boxes . . . . . . . . . . . . . . . . . . . 227

Recordsets for Subforms . . . . . . . . . . . . . . . . . . . . . . . . . . 228

Report Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

Chapter 15 Integrating SQL Script into ASP Code . . . . . . . . 239

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

Building the Components. . . . . . . . . . . . . . . . . . . . . . . . . . 241

ODBC Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

Building SQL Statements. . . . . . . . . . . . . . . . . . . . . . . . . . 250

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

Chapter 16 Access Projects. . . . . . . . . . . . . . . . . . . . 257

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

Differences between Access Projects and Access Databases . . . . . . . 262

Project Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Database Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

Chapter 17 Concluding Thoughts . . . . . . . . . . . . . . . . 287

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Common Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

xi

Contents

Appendix A Answers to Quizzes and Projects . . . . . . . . . . 289

Appendix B Frequently Used SQL Keywords in Microsoft Access. 303

Appendix C Terms and Definitions. . . . . . . . . . . . . . . . 307

Appendix D Microsoft Access Data Types . . . . . . . . . . . . 315

Appendix E SQL Script to Create the Tables in This Book . . . . 317

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333

xii

Contents 

Acknowledgments

I’d like to thank God for giving me the strength, persever￾ance, and guidance to complete this book. I’d like to send a

special thanks to my sisters and brothers: Panzina E. Coney,

Tanya Levin, Reginald Coney, and Timothy Coney. Special

thanks also goes to the staff at Wordware Publishing and to

Wes Beckwith for your patience and for the opportunity to

publish this book. Thank you, Neal Berkowitz, for your hard

work and your expertise. I’d also like to thank the following

people who without knowing it offered inspiration: Thomas

and Debra Brown, Leonard and Yolanda Cole, Teik-Seng Yu

(aka Cowboy), Richard and Gayle Finch, Dr. Dyan

Harvey-Dent, Dion and Stephanie Dixon, Odessa Browne,

Obit F. and Yvonne O. Allison, Mary Carias, Nirmala

Arumugam (aka Mala), Vernon and Yvonne Spellman, Otis

Coney, Tommy and Maryellen Ledbetter, Yolanda D. Love,

and Lashawn Jackson.

Cecelia L. Allison

The computer field is one in which many people freely give

of their knowledge and expertise. I would like to thank the

members of the Metroplex Access Developers who continu￾ously provide insights and suggestions when I am faced with

peculiarities in Access and computers in general. Chuck, Al,

Larry, Toi, Charlie, and everyone else, thanks for the help!

Extra thanks goes to my coauthor, Cecelia, who has kept me

on target, and Wes at Wordware, who keeps pushing me to

finish things.

Neal A. Berkowitz

xiii

This page intentionally left blank.

Tải ngay đi em, còn do dự, trời tối mất!